Preheat oven to 375 degrees with rack in the middle.
Cook onion and garlic in oil with 1/4 tsp salt in a 4-quart heavy saucepan over medium heat until softened, about 5 minutes. Stir in spices and cook, stirring 30 seconds. Add chopped tomatoes with juice and sugar and simmer, uncovered, stirring occasionally, until slightly thickened, about 20 minutes. Remove from heat.
Season shrimp with 1/8 tsp salt, then stir into tomato sauce. Transfer to a 2-quart shallow baking dish and top with feta. Bake until just cooked through, 18 to 20 minutes. Serve sprinkled with dill.