Lightly grease a 3-quart baking dish. Preheat oven to 350°F.
Melt butter in a Dutch oven over medium; stir in onion and garlic, and cook, stirring constantly, 2 minutes. Stir in water and salt, increase heat to medium-high, and bring to a boil. Whisk in grits, and stir in ham; return to a boil. Reduce heat to medium-low, and simmer, whisking occasionally, until thickened and grits are almost tender, 15 to 20 minutes. Remove from heat; add both cheeses, stirring until completely melted. Stir in milk, corn, thyme, pepper, and eggs. Spoon mixture into prepared baking dish.
Bake in preheated oven until golden and cooked through, 50 minutes to 1 hour. Let stand 15 minutes before serving.