Yes it's legal to sell a used mattress either privately or through a furniture store.
There's no law that says that used mattresses cannot be sold either personally or through a furniture store etc.
However it's not really a good idea to buy a used mattress because you never know what actually went on on that mattress you're buying.
There could be hidden body fluids such as sperm, blood, urine etc inside the mattress even if the mattress was cleaned prior to selling it.
A used mattress is something I would never buy used and would rather sleep on the floor or my couch instead.
Used mattresses can also have bed bugs hidden in them which can bite you and be transferred to your house as well as many other types of bugs could be hidden in the used mattress.
So you can buy or sell a used mattress if you want too but I would not recommend you do so.
You can buy cheap mattresses online and not worry about the bed bugs, body fluids etc.