@kendalls5216292 I get your issue here. Totally understand where you are struggling. Since I understand from your post that you are a beginner in AEM , I would first recommend you to go through the Basic AEM architecture. The answer to your entire question resides with the basic architecture of AEM. I searched for the official docs on this but couldn't find it in google search so sharing this instead. https://www.zarantech.com/blog/aem-architecture-explained/ it's the same.
Now coming back to your question, the issue you are struggling here to understand is called Sling Resolution or Sling Resource Resolution. I had recently tried to explain the same with some example in my Linkedin
I would recommend you to read this and let me know any more question on this and we will be happy to help.