The lavatories have them because occasionally some people
will smoke there, and you don't want them to drop the cigarette in the paper trash and kill everybody in the plane when it starts a fire (which apparently
has happened, in the past).
http://www.iasa.com.au/folders/Safety_Issues/RiskManagement/...
But if you google a bit there appears to be lots of fires still, when cigarettes are dumped in trash cans.. so either not all planes have ash trays in the lavatories, or some are too stupid to use them, or maybe they want to hide that they smoke by stuffing the cigarette deep down into the paper trash..