Yes, there is a law that only a professional tour guide can show tourists around Morocco.
The law is to protect tourist from those who will claim to be tour guides and are really just dangerous criminals or prostetutes wanting to exploit or rob the foolish. Unfortunately, the law doesn't distinguish between those bad people and genuine friends and relatives. So occasionally innocent people can find trouble with it. There are ways to avoid it. If you are worried, just hire a guide to go along. Make sure to see his license. He will not be very expensive. Most likely you will not have a problem being without a pro guide outside of the heavy touristic areas, but there is still the possibility. No one really expects to find a tour guide with you in a nightclub, sporting event, shopping at the mall, or eating with you at a restaurant.
It is not really the police you need to be aware of when you are out with your friend. It is the people in the tourist industry trying to protect their own interests. They aren't bad or greedy people, but as the tourist activity in Morocco is slow this year, regular tour guides are struggling. It is easy to find them at the ready to serve you in the touristic areas, but if you are there with a local person they can get annoyed. They all pretty much know eachother as pro guides, so they do take notice of any local people they don't know who are out with what they believe are tourists. If you get stopped by a police officer, it will usually be because he was tipped off by a tour guide that you passed, and the guide noticed you were with a local person. Be aware someone probably followed you for awhile listening to your conversations to determine if your friend was appearing to act as a non-licensed tour guide. We have noticed people who have followed my mother and me, but they usually stop when my husband stands firm and tells them to leave his family alone. A fake tour guide won't do that. I am married to a Moroccan, so we do attract attention as we speak in English.
In the last 6 years we have been stopped only once in the madina near Djamma efna square. It happened only the one time, but once was enough. I keep my marriage license on me to resolve any problems....especially when we visit those kinds of places. We still have good times with our visiting friends, but I go with him when he is showing our friends around popular attractions. If I cannot go for some reason, he will explain he has to avoide the main tourist sites and just take our friends on a walking tour of the souks but he has to have them follow him at a few paces of distance away and keep talk between them at a minimum between stopping points. It may seem kind of rediculous, but it is not really difficult. With the invention of cell phones, if they get separated, it is easy to relocate eachother. Just be careful not to go waving your new iPhone around in the medina as bate to a thief.
I hope you have a nice time in Morocco with your friends.