I was wondering if a spell can become a cantrip if a wizard casts it say 40 times, since the D&D 5e rulebook says cantrips are spells that have been fixed in the caster's mind by frequent use, infusing the caster with the magic needed to produce the spell over and over.
No, not according to the Rules as Written.
As noted in the Player's Basic Rules:
Cantrips—simple but powerful spells that characters can cast almost by rote—are level 0.
The idea behind a cantrip is that it is so simple that you can cast it essentially without thinking about it. In this sense, casting a cantrip is like walking: you don't really think about it, you just do it.
Non-cantrip spells, by comparison, require that you focus more of your attention on casting the spell. This would be more draining to the caster and more comparable to, say, hiking in difficult terrain. You need to pay more attention to what you're doing, and at some point, both your attention and your body become fatigued and you need to rest before continuing.
You could get a lot of practice hiking, but it would never negate the concentration and stamina you need to do it over long periods of time. Likewise, you could get a lot of practice casting more complicated spells, but at a certain point, you're not going to be able to focus on the act without resting.
In this respect, it helps to think of your spell slots as "concentration points". Once you're out of spell slots, you are too mentally fatigued to concentrate enough to cast spells requiring focus. It would also ruin game balance by giving characters way more power than they'll go up against in an encounter balanced for their character level.
Yes, sort of, but not how you want. Wizards get a feature at 18th level that lets them cast one first level and one second level spell at will. This doesn't actually make them cantrips, however. It also has nothing to do with how many times they have been cast.
Allowing what you want would be ridiculously unbalanced. A 5th level wizard could just take a couple months off of adventuring and then be able to cast fireball every round in every fight. The "repeated practice" bit is just flavor.
From the two paragraphs on page 78 of the D&D Players Basic Rules (don't have access to my PHB at work),
Cantrips-simple but powerful spells that characters can cast almost by rote - are level 0.
The important part of the line is simple. A minor effect.
A cantrip is a spell that can be cast at will, without using a spell slot. Repeated practice has fixed the spell in the caster's mind and infused the caster with the magic needed to produce the effect over and over. A cantrips spell level is 0.
The risk here is that in letting a spell that has a level 1 or greater become a cantrip will greatly shift the balance of the game. If a player were to become exceedingly proficient in casting X spell to the extent that it can be used as a cantrip, you have essentially given them an innumerable number of spell slots.
Don't forget that there is an implied level of practice involved, even when your character isn't currently adventuring. The fighters spend their time building up strength and constitution, the rogues keep their dexterity in line, and the wizards keep on learning and practicing spells. That's what's needed to keep a stat (or a proficiency) - if you stop practicing, your body and mind wanes.
So, sure, on an adventure, maybe you cast that particular spell fourty times. Well, big deal - during your half a year at home (/university/...), you cast it a thousand times just for practice. Or maybe even a bit of coin, if it's a generally useful spell.
The cantrips are a bit different - imagine exactly the things you do completely mindlessly, on cruise control: say, just the flick of a wrist to give you light to read books at night, or the cooking spells, or that "remove sweat" spell, or even that low-powered bolt you use ten times a day to kill mosquitoes. You don't think about them, they just pretty much happen when needed, without breaking your concentration one bit.