Last week I flew on a modern B737-700. I noticed that the lavatory was equipped with ashtrays (both on the inside as on the outside) even with the smoking sign on it. Smoking on airplanes has been banned from quite some time now, so why are lavatories still built where ash trays are provided?
Because in the US (where Boeings are made) it's required by law. 14 CFR 25.853(g) says:
(g) Regardless of whether smoking is allowed in any other part of the airplane, lavatories must have 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.
The law may be different in other jurisdictions, of course. Why the law still exists is another question, but either no one found the time to change it (laws are often very difficult to change once passed) or it was a deliberate decision to keep requiring ashtrays in case someone tries to smoke anyway.
EDIT: As commenters have noted, the law I quoted requires ashtrays outside the lavatories but it's still common to find them inside. My guess here is that the ones outside comply with the letter of the law, whereas the ones inside comply with the intent, i.e. they're there because if someone does light up, it will be inside the lavatory and not outside in plain view. This 2012 article quotes an anonymous FAA source as saying that people continue to smoke on aircraft so it still makes sense to have them for safety reasons. That raises the question (again) of why the law doesn't fully reflect reality, but that's neither unusual nor unique to aviation.
It's for safety. Smoking may be prohibited, but if a passenger smokes anyway, you don't want the remains of the cigarette to start a fire due to improper disposal, as probably happened with Varig Flight 820:
A possible cause of the fire was that the lavatory waste bin contents caught fire after a still lit cigarette was thrown into it, the FAA issued AD 74-08-09 requiring "installation of placards prohibiting smoking in the lavatory and disposal of cigarettes in the lavatory waste receptacles; establishment of a procedure to announce to airplane occupants that smoking is prohibited in the lavatories; installation of ashtrays at certain locations; and repetitive inspections to ensure that lavatory waste receptacle doors operate correctly".
Here is the latest revision of FAA Airworthiness Directive 74-08-09.
"One size fits all". Since smoking is/may be allowed on some foreign airlines, it would be silly for Boeing and other manufacturers to build airliners that were smoker-equipped and those for non-smoking. It is easier and less costly to install ashtrays on all aircraft and just keep the no smoking light on for those flights where smoking is prohibited.