I'm not the ashtray expert, but I have experienced this a few times and was able to fix it by removing the entire ashtray assembly and adjusting the small tab on the left side. I'm not sure why this tab even exists, but if it's in the wrong position your ashtray won't lock. The whole thing looks a bit Rube Goldbergish to me.
To remove the ashtray, You have to start with the two screws inside the center console, then remove the console and the gear shifter trim (you'll have to insert the key and move the shifter to N). Then you can get the trim around the ashtray out. Eject the ashtray liner with the lever lock and there are two small screws under it, at the bottom of the ashtray. The screws tend to fall to the bottom of the ashtray and into a black hole. You'll have fun trying to figure out where they went inside the assembly but you'll eventually find them. A magnetic Phillips-head screwdriver might be helpful here for removal and installation.