Defrost the spinach. Peel potatoes, cut in half and cook in boiling salted water for about 20 minutes. Clean, peel and slice carrots diagonally. Cook carrots in boiling salted water for about 12 minutes until al dente.
Meanwhile peel the onion and garlic. Chop the onion finely. Press the garlic through a garlic press. Heat the oil in a pot. Fry the onion and garlic until transparent. Add tomato paste and spinach and fry briefly.
Deglaze with tomato juice. Season with salt, sugar and pepper. Wash thyme, dab dry and pluck leaves from the stalks, except for some for garnishing. Add to the spinach. Drain the potatoes.
Add milk and butter. Mash everything with a potato masher to a smooth mixture. Season with salt and nutmeg. Layer carrots, ham and spinach-tomato mixture in an ovenproof dish.
Pour the mashed potatoes into a piping bag with a star-shaped spout and spray diagonal strips onto the casserole. Bake in the preheated oven (electric cooker: 200 °C/ convection oven: 175 °C/ gas: level 3) for approx. 15 minutes.
Remove the casserole from the oven and garnish with thyme.