Preheat oven to 350 degrees F. and grease an 8x8 baking dish with cooking spray or softened butter.
Slice the squash into 1-inch rounds.
Melt 4 tbsp of butter in a large skillet over medium-high heat. Add the squash and onions, cover, and cook for 10 minutes, stirring occasionally. Stir in the fresh garlic, Italian seasoning, sugar, and season with salt and pepper.
Place the squash mixture in a colander and let it sit for 5 minutes.
In a large bowl, mix the shredded Gruyere cheese, mayo, sour cream, and eggs until well combined.
Add the onion and squash mixture into the mayo mixture and mix well. Season with salt and pepper.
In a medium-sized bowl, mix the crushed ritz crackers and 2 tbsp melted butter until well combined.
Place the squash mixture into the prepared baking dish and top it off with the ritz cracker mixture. Bake for 25 minutes uncovered and enjoy!