No, you do not necessarily have to cook onions before putting them in meatloaf. In many meatloaf recipes, raw onions are commonly used and mixed directly into the ground meat along with other ingredients. When the meatloaf bakes in the oven, the onions will soften and cook along with the rest of the meatloaf, infusing it with flavor.
However, if you prefer a milder onion flavor or want to ensure that the onions are fully cooked and softened, you can sauté the onions in a pan with a little oil or butter before adding them to the meatloaf mixture. This will help to release their natural sweetness and make them more tender.
Ultimately, whether you choose to use raw or cooked onions in your meatloaf is a matter of personal preference. Both methods can result in a delicious meatloaf, so feel free to experiment and find what works best for you.