How do I op a user who has spaces in their username on a Minecraft server?

The quotation mark method seems like it would work, but it doesn't in /op. However there are still other methods that work. As the other answer mentions, you will be able to get a player UUID from that person in the chat.

But what if the player hasn't chatted recently?

If your player hasn't chatted recently, you won't see their username in chat and won't be able to get a UUID. Sure, you could just ask them to send a chat message, but that will get tricky when you're trying to deop a person, because they can resist you by simply not sending any chat messages.

But, there is yet another method that is the most elegant:

Specified the player to be grant op to. In Java Edition, must be a collection of game profiles (player profiles), which can be a player name (must be a real one if the server is in online mode), or a player-type target selector.

A target selector (@p, @r, @a, @e) can also be used to select a player. And target selectors have a name argument to select targets by name, and unlike /op directly? It allows " syntax.

This is the command to use:

op @a[name="a name with spaces and \"quotation marks\""]

If you hover over the user's name in chat, you'll see their UUID, e.g. 584fb77d-5c02-468b-a5ba-4d62ce8eabe2. You can use this in the /op command instead of a username: /op 584fb77d-5c02-468b-a5ba-4d62ce8eabe2