Sure it's legal.
At the time you made your offer, the seller was accepting only cash offers.
Sellers change their minds. They'll put a house on the market for $300,000, reject one offer for $280,000, then 3 months later accept an offer for $275,000. They'll get an offer contingent on the buyer selling an existing property and reject it. A few months later, with their house on the market, they'll get another offer contingent on the buyer selling a property . . . and accept it. They'll put a house on the market and, when it doesn't sell, they'll rent it.
It's legal for sellers to change their minds on what they consider an acceptable offer. (Once both parties have signed a contract, then they can't change their minds . . . to oversimplify. But without an agreement agreed to by both parties, mind-changing is par for the course.)
I agree with John that it would have made sense--once the sellers decided they didn't need an all-cash offer--for them to have contacted you and invited you to resubmit your offer. They may have figured that--months later--you would no longer be in the market. So it sounds as if the sellers made a number of strategic errors. But doing so isn't illegal.
Hope that helps.