That does not make it illegal. You asked if it was illegal. It is not.
Things may have changed, or perhaps they thought it would work out okay, but it didn't. We don't know why they've had this sudden change of heart, perhaps there is another reason they weren't happy with you and they are just using this reason. If it meant you keeping your job, then boyfriend could have found a ride home, waited for you to get off work, or he took the vehicle and picked you up, public transportation, etc. I'm just saying, you could have made sure you could work when they needed you, not expected the employer to adjust to your needs.