Melt butter in a skillet over medium heat. Cook and stir sweet onion in hot butter until browned, 5 to 7 minutes; transfer to a bowl. Add mayonnaise to the onion and stir; pour into a 9x13-inch baking dish. Sprinkle Swiss cheese over the mixture.
Bake in preheated oven until the top is bubbling and lightly golden, about 35 minutes.