The question of how the universe was created is a topic of ongoing scientific research and philosophical inquiry. The concept you mentioned, which states that matter and energy cannot be created or destroyed, is known as the principle of conservation of mass-energy, which is a fundamental principle in physics.
One hypothesis about the origin of the universe is the Big Bang theory. According to this theory, the universe originated from a singularity—a state of infinite density and temperature—approximately 13.8 billion years ago. The Big Bang theory does not violate the conservation of mass-energy because the total mass-energy of the universe is considered to be constant. In this theory, the universe began expanding from an extremely hot and dense state, and as it expanded, matter and energy were distributed throughout space.
However, it's important to note that the exact nature of the Big Bang and the origin of the singularity are still the subject of scientific investigation. The laws of physics, as currently understood, break down at the singularity, making it difficult to precisely describe the conditions at the moment of the universe's creation. Research in cosmology and theoretical physics, such as quantum gravity and string theory, aims to provide further insights into these questions.
It's worth mentioning that the concept of the conservation of mass-energy applies to the total amount of matter and energy in a closed system. The origin of the universe, being an event that potentially involved the creation of space and time itself, falls outside the scope of a closed system. Therefore, discussions about the creation of the universe often delve into philosophical and metaphysical domains, exploring different hypotheses and viewpoints.