Preheat your oven to 375°F and lightly grease a 9x13-inch baking dish. This temperature ensures the ravioli cooks through without burning the cheese.
Heat olive oil in a large skillet over medium heat. Add the diced onions and cook for 3-4 minutes until they begin to soften and become translucent.
Add the garlic to the onions and cook for another 30 seconds until fragrant, being careful not to burn it as this can create bitterness.
Brown the ground beef in the same skillet, breaking it up with a spoon as it cooks. Season with salt and pepper. Cook until no pink remains, about 5-7 minutes.
Stir in the marinara sauce, Italian seasoning, and red pepper flakes (if using). Bring to a simmer and cook for 5 minutes to allow the flavors to blend.
Arrange half of the ravioli in a single layer on the bottom of the prepared baking dish. No need to cook the ravioli first—it will cook perfectly in the oven.
Spoon half of the meat sauce over the ravioli layer, spreading it evenly to cover all the pasta.
Sprinkle 1 cup of mozzarella and ½ cup of parmesan evenly over the sauce layer.
Repeat the layers with remaining ravioli, sauce, and cheeses, finishing with a cheese layer on top.
Cover the baking dish with foil and bake for 25 minutes, then remove the foil and bake for an additional 5-10 minutes until the cheese is golden and bubbly.
Let the dish rest for 5-10 minutes before serving. This allows the layers to set and makes serving much easier.
Garnish with fresh basil if desired before serving.