Preheat the oven to 350 degrees F (175 degrees C). Spray a 9x13-inch pan with cooking spray.
Spray a small pan with cooking spray and heat over medium heat; stir in onion. Cook and stir until the onion has softened and turned translucent, about 5 minutes.
Transfer onions to a large bowl and mix in hash browns, ham, taco-flavored cheese, and chile peppers. Layer in the bottom of the prepared pan.
Whisk eggs, milk, sour cream, and taco seasoning together in a bowl. Pour on top of the hash brown layer.
Bake in the preheated oven until a knife inserted into the center comes out clean, 45 to 60 minutes; check every 5 minutes toward the end.
Remove from the oven and spread Mexican cheese on top. Return to the oven and bake until cheese is melted, about 3 minutes. Let casserole stand for 5 minutes to set before serving.