Question: I'm going to a concert to Vienna on Saturday (two days). I just realized that there aren't any trains back to my home in the night so I'd have to wait til the morning until the first train leaves again (5.43 AM).

I don't know when the concert will end, but expect it to be somewhere between midnight and 2 AM. 

Now, I don't want to spend 40 € on a hotel room, especially when I can only "book in" in the middle in the night and have to leave really early. 

Is there any safe space in Vienna for a young woman to stay for a couple of hours in the middle of the night? I don't need to sleep, I just don't want to get raped. 
Are train stations safe there? Or are there any cafés which are open 24/7? MacDonalds?

Answer: 
If your main concern is that you have to pay for a hotel room for the entire day but would spend only a couple of hours in it, maybe you could opt to leave Vienna later in the day or early evening instead of early morning. 

That way you can relax after a possibly tiresome concert, wake up fresh, then either spend time in the room or explore Vienna a bit (if you haven't already) and then take a train to your final destination later in the day. I feel this option would be safer than opting to stay out in the open (even if its in a 24-hour McDonalds). You could cut your cost by some euros by staying in a dorm instead of a hotel room.
As you are staying on a weekend, there will be plenty of bars, clubs and other entertainment locations open till the early morning. Some of them may be loud, some quiet, so you can pick depending on what you are likely to be in a mood in after the concert.

Here's an english website listing many options: <https://www.wien.info/en/lifestyle-scene/nightlife>

Note that in general, Vienna is considered a very safe city. So you should most likely be fine no matter where you stay, but as everywhere else, a public place is a good option.