A twin-sized mattress can be carried on a bike by using the Bikes-at-Work Trailer. If you need a bike trailer just temporarily, you may get lucky and live a city where one might be rented or borrowed. Call your local bike shop to ask around.
In the photo above, I put some plywood underneath the mattress to stabilize it.
The Bikes-at-Work Trailer website features a photo of what appears to be a queen-size mattress and springs being carried vertically on one of their trailers, bu using some vertical posts to stabilize the load. Unfortunately, I don't have details on how posts are attached.
If you are shopping for a new mattress, you could consider one of the "Mattress in a box" options which can be shipped straight to you in a box. But keep in mind those mattresses are compressed at the factory with special equipment and never get that small again. Maybe since they are made of compressible foam, you can fold a used one in one half for transport by trailer as I did below, but I haven't personally tested that.
The only time I've tried to carry a larger mattress, a queen size, was when I found dumped on the side of the ride and carried it to the city dump. I folded the mattress in half for that, which not be something you want to do with a new mattress!
One mattress store solved this problem by building a special wide trailer:
If you have success transporting a mattress that's queen size or king size by bike, leave a comment below to let me know!