Yes, you can. According to the Mexican government's official entry requirements, your passport only needs to be valid for the duration of your stay—not necessarily six months beyond entry.
While not legally required, having at least 6 months of passport validity is strongly recommended. It prevents potential issues with airlines (which may enforce stricter rules) and ensures smoother entry if your plans change or you need to extend your stay.
If your passport expires in 3 months but your trip is only 2 weeks, you're legally fine. But renewing before travel eliminates stress and airline complications.