The short answer is that the number of megapixels is not, and has never been, the most important metric of camera quality.
Phone cameras are complex assemblages of lots of bits of software and hardware, so it doesn’t really make sense to isolate one specification amongst many (e.g. number of cameras, combination of different focal lengths, combinations of different apertures, ISO and dynamic ranges and so on, before you even start talking about the computational stuff).
I doubt Apple is sticking to 12MP for now because of cost, and I certainly don’t think it’s about memory. Rather, I think they’ve made a particular set of trade-offs that they think works best for now.