When I worked for Mazda, this was a common problem for me. Most likely you had the key fob in your pocket and something kept pushing the button while you were out of range of the car. This puts the fob in "battery conservation" mode. The owner's manual has the procedure to get out of that mode so the fob will work normally, but IIRC, the procedure was like this:
With the ignition off but you near or in the car, push the lock switch on the side of the fob several times quickly in 5 seconds or so. The doors will lock each time and the horn will beep after the first time. The little red light by the button will come on and stay on. Now push and hold the button. The doors will lock and the horn will beep again after a couple of seconds, and then you are out of battery conservation mode. The fob should then work normally without having to hold it near the start button.
If the red light doesn't come on and stay on, the battery is probably low. Change the battery (number 2025 for yours), then repeat the procedure. Newer Mazdas take the 2032 battery.