So basically it's a series of tests conjured up by Sir Gawain's mom to toughen him up while also gauging his moral compass in which he ends up failing just about every one of them. These are also a few characters who act as guidance as a way for her to directly speak to him without revealing her true intentions, to make him think twice. When he meets The Green Knight, instead of making good of his promise, he runs away. Later we see how everything in his life has gone wrong, right up until his ultimate demise, which also turns out to be a vision of what would have happened had he not changed his ways. He finally realizes all the bad things he's done and accepts his faith and the movie ends. But there is a short scene after the credits where we see a child playing in the background, presumably his so we can safely assume that he doesn't die and returns home, having learned his lessons, a changed man. It's mom's elaborate scared straight pranks after all.