The simple question of the origins of the mitochondria and chloroplast takes us all the way back to the origins of complex organisms.
Unlike the other organelles, which originated inside the plasma membrane, the mitochondria and chloroplast were once primitive but independent prokaryotic cells, most likely a type of bacteria. The endosymbiotic theory proposes that ancient prokaryotes engulfed each other around 1.5 billion years ago. Although this would usually result in the unfortunate engulfed cell becoming a meal for the host cell, for some reason, sometimes the digestion failed. Eventually, the swallowed cells were allowed to just hang out there, because the host cells realised they were beneficial.
To understand why, we have to understand how organisms are classified based on their metabolism. There are two main types: autotrophs, which make their own food, and heterotrophs, which rely on energy made by other organisms. Within each category are phototrophs, which derive their energy from light, and chemotrophs, which derive their energy from chemical compounds. This table makes it pretty clear:
(Image Credit: Pearson Education)
Mitochondria are aerobic heterotrophs, meaning they create energy using oxygen, and chloroplasts are photoautotrophs, meaning they produce energy from light. When the mitochondria was stuck in the host cell’s cytoplasm, surrounded by other bits of half digested food, they had plenty of fuel to take in for themselves and convert it into cellular energy. Soon they must have been so bursting with energy that some leaked out, allowing the host cell to use it for their own cellular activities.
Having an houseguest that churns out energy would have been a huge advantage for the host cell, since it wouldn’t have to go to the effort of making its own. The mitochondria basically acted like an installed battery, and in return, it was given protection by the host cell. Something very similar would have happened with chloroplasts, though chloroplasts would have created energy from light rather than half-digested molecules. As the host and guest cell benefit from each other, the partnership is called a symbiotic relationship.
But eventually, the two came to depend on one another—the host cell stopped producing much energy by itself, and the guest cell stropped producing genes for protection. The relationship became more and more dependent, until the mitochondria and the chloroplast simply become part of the eukaryotic cell.
There’s significant evidence supporting this theory. Firstly, the mitochondria and chloroplast each have two membranes, one enclosing the other, as if they had one originally and then were given another when the host cell engulfed them.
Both also have their own DNA, which is circular in nature like prokaryotic DNA instead of the linear DNA of eukaryotes. They use it to produce proteins and enzymes. They also divide by binary fission (splitting one parent cell into two identical daughter cells) just like bacteria, and they don’t use vesicles to send or receive substances from other organelles.
It’s like the Endomembrane system is a bunch of kids who have grown up together, while the mitochondria and chloroplast are those weirdos who have just moved into the neighbourhood and like, absorb sunlight and radiate energy and all kinds of X-men-esque junk.
Further resources: Animation or read about Lynn Margulis, who first proposed Endosymbiosis