You’re right, because hair has a terminal length! Your hair falls out naturally and over time the chances are the hairs that fall out will be the long ones, you end up with a practically maximum hair length.
It doesn't know, it just seems to because of the overall effect. There is a natural grow/stagnate/drop-or-die/restart cycle for each follicle. This varies from person to person which is why some can grow longer hair than others if they want to. It isn't all in sync, which is why we seem to have relatively constant growth rather than a grow/moult cycle as see in many fully haired animals (actually, they also have the shorter cycle like ours and moulting is just the drop/die part happening sooner for a time).