Silly as it may seem, this law is enforced atleast due to one incident were either a DC-9 or 727 actually crashed because of a fire in a rear toilet due to a cigarette being disposed in the trash can. Hence ashtrays on lav doors. It still holds value today as where is a pax most likely going to smoke up?
The ashtray provides a safe place to dispose of the cigarette. Though a cup with water in it works too. Also a reason why many aircraft are fitted with fixed mini fire extinguishers in the lav bins.
Silly as it may seem, but many of us have seen how the self loading luggage checked their brains at the check in desk