How does it happen?
Well, let's see. Teachers often mistake motivation for talent, and the lack of motivation for lack of talent. The abilities of certain personality types (e.g. "FP"s) are more likely to be noticed. Teacher may not be giving students any material aimed beyond grade level for work or assessment. Teacher may have personal experience of other gifted students and may be thinking "This student is not like those students." Student could be "punishing" a teacher he or she does not like by turning in substandard work.
There are many ways it could happen.