This is quite frankly not true.
Fish aren't the dumb animals with 3 second memories many people seem to assume they are, its nothing more than a myth.
They possess remarkable intelligence, and definitely are just as well aware of their confines and environment as any captive marine mammal, some more so than others.
I still remember my rainbow fish i had some years ago.
They were quite small and at a glance could easily fit in a small 5g tank, but the reality was quite another.
Confined in such a small space they became frantic and panicky, and kept flying into the glass at breakneck speed and would not stop, no matter what.
They didn't calm down and become content until I moved them over to a 27g tank, even though to them it was like putting a P. Volitans in a swimming pool.
So yes, fish can definitely know that they are in an aquarium, and not the ocean or a lake.