Actually this isn't a question only for big four but what made me think of this question has to do with the Big Four. I noticed Megadeth is going on before Slayer. I was suprised because Megadeth has sold more albums and enjoyed more success.

I have always been curious how or who determines the band lineups in festivals whether it be the big 4 or some other festival. Can anyone offer some insight?

randomly, nobody in charge would give a **** who goes first or last.
Quote by PwarDuex
your name is about as funny as a burning orphanage

Usually it is done by "size" - seniority, popularity, etc. There's always exceptions. And some people may argue Slayer is "bigger" than Megadeth.
In other festivals, it will have lots to do with when they are available during that day. For example, if they want Behemoth to play, but they need to catch a plane at 9pm to get to the next festival or whatever, then obviously they need to play before they have to go to the other place.