It is not code in most places for a dryer to be vented through the roof as it's better to vent the dryer through a wall.
Some places do allow for a dryer to be vented through the roof but if you can you should vent the dryer through the wall which provides easier access for cleaning.
Most building codes recommend that you vent a dryer through a side wall that is near ground level for easiest access to clean the dryer vent.
It is safe to vent a dryer through the roof when installed properly and when you ensure you keep the dryer vent and tubes clean and free of lint.
However if not cleaned often enough then it can possibly start a fire when you have the uncleaned dryer vent through the roof.
The same is true with a dryer vented through the wall if it's not kept clean.
Dryer vents through the wall are easier to keep clean than dryer vents through the roof but they both can start a fire if not kept clean.
Builders often put dryer vents on roofs for a variety of reasons which includes aesthetics and space efficiency and to prevent animal entry.
Roof dryer vents can discourage animals from getting into the dryer vent like they would if it were on the wall lower to the ground.
Roof dryer vents are also more aesthetically pleasing than dryer vents mounted on the outside wall.
venting a dryer through the roof can also be space saving for homes that have limited exterior wall space like condos and town houses.
However venting a dryer through a roof makes it harder to keep the dryer vent clean and free of lint which can buildup in the dryer vent.
With a roof dryer vent you would need to get up on the roof to get the lint clean from it.
Dryer vents that are vented through the wall are easier to keep clean than roof dryer vents.
Wall mounted dryer vents also make the dryer work less hard.
Roof dryer vents causes the dryer to work harder to dry the clothes.
My house had a dryer vent on the roof when I bought it and I installed a wall mounted dryer vent instead which is much better.
Venting dryers to a roof termination or roof cap instead of through a wall is very common in the south.
This is because many laundry rooms are located in the middle of the house, and so many homes are single story with easy to walk on roof slopes (about 6/12), venting your dryer through the roof makes the most sense in those cases (due to the shortest run, with the least amount of elbows).
However if your laundry room has an exterior wall then it's best to vent the dryer through the wall instead of the roof.