Answer:
I believe that it has its roots in “Pancake Tuesday”. In the old Church, people were required to give up dairy products and eggs for Lent, so they made pancakes on Shrove Tuesday and had a bit of a party before they had to start the 40 day fast of Lent. And back then it was a forty day fast - up until the twentieth century, on most weekdays, you could only have one full meal during Lent, and two snacks that together did not make up a full meal.
Knowing people, since it was their last last of a full meals, eggs, milk, etc. they started turning it into a full fledged party, not just a pancake dinner. And given man’s fallen nature, we tend to overdo things. There were other things which went into the development of Carnival but it started as one last party before the long stretch of Lent.