Where does the energy required to turn ADP into ATP come from?
This is a common problem when asking about the explanations for things that happen in a biological context.  When you ask for why something happens in biology, the answer to that question depends on what, specifically, you want to know.  For example, the same question, "Why can humans see more colors than dogs?" can be answered using a physiological mechanism (Humans can see more colors than dogs because we have an additional cone type in our eyes), or an evolutionary explanation (Humans can see more colors than dogs because our ancestors were under selective pressure to be able to identify ripe fruit).  Both of these responses would be correct but they are answering from different perspectives.

The question of where the energy comes from to phosphorylate ADP is another one of these questions that can be answered in a couple of different ways.  The immediate mechanism for providing this energy is the proton gradient between the intermembrane space of the mitochondria and the mitochondrial matrix in the case of Cellular Respiration and the proton gradient between the Thylakoid Lumen and the Stroma in the case of Photosynthesis.  But where did the energy ultimately come from?  The sun.  In the case of Photosynthesis, it is energy from the sun that drives the photosystems that generate that proton gradient in the first place.  In the case of your own body, you either eat a plant or eat an animal that ate a plant that got its energy from the sun in the same way, and then use the chemical energy contained in that food to sustain your own proton gradient.  Either way, the energy ultimately came from the sun.  It's just that the proximate (immediate) explanation is a chemical one driven by a chemiosmotic gradient maintained either by sunlight and water in the case of photosynthesis or sugar and oxygen in the case of cellular respiration.