It's a prototypical in-flight brain teaser - which comes on with the dusk and soon vanishes as the wheels touch the ground at dawn.
If smoking is legally banned in the aircraft's, what for are the ashtrays?
It's required by the law.
According to title 14 of the Code of Federal Regulation (CFR) Chapter I, Sub Chapter C, Part 25, Sub Part D, Section 25.853 and Paragraph g, "regardless of whether smoking is allowed in any other part of the airplane, lavatories must have a self-contained, removable ashtrays located conspicuously on or near the entry side of each lavatory door, except that one ashtray may serve more than one lavatory door if the ashtray can be seen readily from the cabin side of each lavatory served."
If more than 50% ashtrays are broken or not in a condition to be used than they should be repaired within 72 hours i.e. 3 days.