Why does Apotheke become masculine in the second example? In der Apotheke.
It's not masculine. die changes to der because of the locative preposition in.
Woah not so fast... what are locative prepositions?
Locative prepositions or more commonly called "Prepositions of Place" (on, behind, in, beside, over, etc.) give information about the place. That means, they are the answer to the questions:
As I was saying, prepositions of place are a bit tricky in German.
German is so difficult...
Hey, don't worry, it's not impossible. It is important for Germans to define whether something is in a place "statically" or is moving towards that place. That distinction you can see in the article. Take a look:
1. We call these changes in the articles "cases". The first basic case is "nominative": der, die, das, die.
2. The "accusative case" den, die, das, die is used after local prepositions if it is the answer to the question WOHIN? (English: where to?)
3. Then, the "dative case" dem, der, dem, den is needed after local prepositions, but in case it's the answer to the question WO? (English: where?)