Why does hair know when it needs to stop to grow
That's an awesome question! Let me help you rephrase, as I don't have a direct answer; why does hair stop growing at certain lengths, and differentially at various locations on the body?

There are three stages to hair growth:


Anagen phase- growth
Catagen phase- transition
Telogen phase- rest
(then falls out!)


You're asking why and how the anagen phase stops, or more concisely, what processes cause anagen phase to cease and proceed to transition to a degenerated rest. 

The indirect answer I have for you is this: there doesn't exist a definitive mechanism for how the the telogen phase is induced- that is to say that the process by which the hair-producing follicle "turns off" it's cycle to come to a halt has not yet been fully elucidated in the literature and remains a discovery to be made.

I hope I've helped you understand your targeted question