What does “do not shave your beard” mean, Lev 19:27 and Lev 21:5?

There are a couple of verses in Leviticus which seem to indicate that it is wrong to shave or trim your beard.

Lev 19:27  You shall not shave around the sides of your head, nor shall you disfigure the edges of your beard.

Lev 21:5  ‘They shall not make any bald place on their heads, nor shall they shave the edges of their beards nor make any cuttings in their flesh.

Some take these verses to mean that you should not shave or even trim your beard at all, but just let it grow as long as it gets.

Many Bible commentaries explain that the nations surrounding ancient Israel practiced trimming their hair and beards in a particular way (to produce tufts or hair or bald spots, for example) as a way of worshipping their pagan deities.

God did not want ancient Israel to copy the practices of the pagan nations in their worship of Him. 

Deu 12:29  “When the LORD your God cuts off from before you the nations which you go to dispossess, and you displace them and dwell in their land,
Deu 12:30  take heed to yourself that you are not ensnared to follow them, after they are destroyed from before you, and that you do not inquire after their gods, saying, ‘How did these nations serve their gods? I also will do likewise.’
Deu 12:31  You shall not worship the LORD your God in that way; for every abomination to the LORD which He hates they have done to their gods; for they burn even their sons and daughters in the fire to their gods.
Deu 12:32  “Whatever I command you, be careful to observe it; you shall not add to it nor take away from it.

God commanded ancient Israel to destroy the pagan places of worship.

Deu 12:2  You shall utterly destroy all the places where the nations which you shall dispossess served their gods, on the high mountains and on the hills and under every green tree.
Deu 12:3  And you shall destroy their altars, break their sacred pillars, and burn their wooden images with fire; you shall cut down the carved images of their gods and destroy their names from that place.
Deu 12:4  You shall not worship the LORD your God
with such things.

God wanted ancient Israel to completely purge the land of any vestige of paganism and for ancient Israel to have nothing to do with the religious customs and practices pagans.

Conclusion

Leviticus 19:27 and Leviticus 21:5 provide some specific examples of the more general command to not copy the religious customs of the pagan nations.  They are not saying it is wrong to be clean shaven or to trim your beard.