In the Disney classic Aladdin (1992), Aladdin is warned not to touch anything except the lamp. But Both he and Apu touch the magic carpet, Carpet. Why was Carpet excluded from that rule?
Because they never touched it with their hands with the intention to take it like Abu did with the diamond/ruby shiny thing. They stood on it with their feet, which is basically what carpets are for anyway. I know technically touching would mean touching, but I think it didn't apply when they stood on the carpet, because they (the writers/studio etc) needed them to interact with carpet at least a little, eg standing on him, to wake him up and notice there was people in the cave for the first time in a millenia to give him a reason for interacting with them. Plus, it's a cartoon with a parrot that has bigger vocabulary than the dictionary, a genie, a talking panther cave, and many more things that are way weirder than why the cave didn't collapse when they stood on the rug.
I don't know if there is a canonical answer here but for me, the implication is that they are not to touch any of the treasure. After all they were touching the ground by walking on it, so clearly "touch nothing", did not literally mean to touch nothing.
But then one could argue that a magic carpet is part of the treasure as well so it should still apply to the "touch nothing" statement. If we're strictly talking about the Disney cartoon, one could say that the carpet didn't apply because it was alive. Also the carpet initiated the physical contact if I remember correctly which makes it unfair to include in the "touch nothing" rule. They didn't touch the carpet, the carpet touched them.
But if you ask me, I think the "touch nothing" rule was simply meant to apply to the gold and silver and gems that one would obviously be tempted to fill one's pockets with.
One should also note that depending on the version of the story, there may or may not have been a magic carpet. According to Wikipedia:
Aladdin, the 1992 animated feature by Walt Disney Feature Animation (possibly currently the best known re-telling of the story). In this version several characters are renamed or amalgamated (for instance the Sorcerer and the Sultan's vizier become the same person, named "Jafar", while the Princess is re-named "Jasmine"), have new motivations for their actions (the Lamp Genie now desires freedom from his role) or are simply replaced (a magic carpet fills the place of the Ring Genie in the plot, while a royal "magic ring" is used by Jafar to find Aladdin). Names from and elements of the 1940 live-action The Thief of Baghdad are borrowed (for instance, the names "Jafar" and "Abu" and the Sultan's delight in toys). The setting is moved from China to the fictional Arabian city of Agrabah, and the structure of the plot is simplified.
The magic carpet was likely brought into the 1992 Disney version of Aladdin because of the popularity of a flying magic carpet in Middle Eastern folklore.
EDIT: Per Richard's comment, the movie script for Disney's Aladdin actually condemns them as follows
Cave: You have touched the forbidden treasure! (ABU places the jewel back into the paw, but the jewel and the shrine melt into lava.) Now you will never again see the light of day!
This line indicates that what was not to be touched was the treasure itself and not absolutely everything in the cave.
The carpet was not a piece of the "forbidden treasure". As a living being, the carpet was a prisoner of the cave, just like Aladdin and Abu.
The carpet doesn't touch the treasure, because somehow it knows what will happen. When Abu starts walking towards the ruby, the carpet freaks out, obviously knowing what's coming.