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.