Depending on one's stage of musical development, counting can take on a number of functions.
For beginners, it serves to introduce basic musical structure. It is here at this stage where many obtain the impression that counting is laborious and counter intuitive to the freedom of musical expression. From the way many students are taught it is not surprising. Counting as if just reading numbers aloud certainly is boring and unmusical. More on this later...
For intermediate students it can serve as a reminder that rhythms are not static units with labels such as half, quarter, eighth - rather rhythmic units with duration that take place in a temporal framework which have beginning and end points. IMO not fully understanding rhythmic duration is one of the challenges intermediate students face. The problem can manifest itself in those various rhythmic passages that go wonky, when everything else surrounding it seems fine, yet the student remains totally oblivious to the problem. Counting usually fixes the problem quickly, yet there may be many instances where the student does not know how counting fixed it, and may even regress to the problem practicing at home when not counting.
More advanced students will learn that certain recurring rhythmic patterns stored in their toolbox ready to use when needed. The would mean one would not need to work out the rhythm as it is already familiar to them. Similar to how one learns to read: going from alphabet, to words, to sentences, to paragraphs, to meaning. For example, knowing how execute a 3 against 2, one could just insert it as a unit within the main beat counts.
Undergrad students will learn the ins and outs of rhythm and how to work with it. Counting still plays a large part in developing rhythmic accuracy and learning how to problem-solve difficult rhythmic passages. For classical musicians, rhythm is often the weakest skill and it will be uncovered and dealt with rigorously in first year foundations courses.
For 3rd and 4th years and those pursuing advanced music study, one may learn how musical expression is tied into the organizational rhythmic structure. Instead of making music by simply feeling or being emotional, one can learn how to strategically place expression at certain beat counts a measure. From this music is not perceived as being merely emotional, but progresses to be coherently evocative with an articulate resoluteness within its execution.
Count with a purpose. Recall an actor reciting Shakespeare. Are you just hearing words or is there more? When counting in music, strive to be musical in your counting. If it is happening in the music, have the inflections of your voice reflect that in the counting. Count as if you were singing. I have had some students naturally sing the counting without any instruction from me to do so, and in such case the counting felt and sounded like it was part of the music.