That's due to encoding specificity. You aren't just learning the 'thing' but the context in which you learned the thing:
https://en.wikipedia.org/wiki/Encoding_specificity_principle
It's better to learn things in or close to the contexts in which you will use them. That's the heart of situated learning / problem-based learning / simulations, etc: https://en.wikipedia.org/wiki/Situated_learning