Melt butter in a saucepan and cook minced onions until soft and translucent. Stir in flour to form a paste and cook briefly. Slowly whisk in milk until smooth and thickened into a creamy sauce.
Remove sauce from heat and mix in diced ham, chopped spinach, and most of the shredded cheese. Stir until cheese melts smoothly into the mixture. Season with salt, pepper, and a small pinch of nutmeg.
Roll out thawed puff pastry sheets and cut each into four equal squares. Keep pastry chilled until assembling so it puffs nicely in the oven. Cold pastry ensures better layers.
Place pastry squares onto a lined baking sheet. Spoon filling into the center of each square and add a sprinkle of extra cheese. Fold pastry corners slightly toward the center, leaving the middle open.
Mix egg and water, then brush lightly over pastry edges. Bake in a preheated oven at 400°F until puffed and golden brown. Let cool slightly before serving so the filling sets.