Preheat your oven to 350°F (175°C).
In a large skillet, heat the olive oil over medium heat. Add the diced onion and cook until softened, about 5 minutes.
Add the minced garlic and ground beef to the skillet. Cook until the beef is browned, breaking it apart with a spoon, about 7-10 minutes. Drain excess fat if necessary.
Stir in the diced tomatoes, cannellini beans, beef broth, oregano, basil, salt, and black pepper. Bring the mixture to a simmer and cook for 10 minutes, allowing the flavors to meld.
If using, stir in the cooked pasta and chopped spinach, mixing until the spinach wilts slightly.
Transfer the mixture to a greased 9x13 inch baking dish. Sprinkle the mozzarella and Parmesan cheese evenly over the top.
Bake in the preheated oven for 25-30 minutes, or until the cheese is bubbly and golden brown.
Let the casserole cool for 5 minutes before serving.