The phrase "the fuck" in this context is called an Expletive attributive, which essentially refers to words that have no effect on the meaning of the sentence, but indicate that the speaker feels strongly about it. Thus, the phrase's meaning is simply "Do what you want", which works grammatically. Since "The Fuck" doesn't change how any of those words relate to each other, the full version with the expletive is also "fine".
This isn't the most standard format for the expletive to take though. A more formally accurate version would be "Do what you fucking want", since "fucking" is more unambiguously an adverb, though I also doubt that many people worry about the grammaticality of their expletive attributives. I don't actually know the origin for using "The fuck" in this sense, but it's essentially accepted usage.
Less formally, I would prefer "Whatever the fuck you want". The main reason is to avoid overlapping the extremely well-known phrase "What the fuck"; if someone starts parsing the sentence and sees "What the fuck" they will read it as the combined phrase rather than separating out "the fuck" as an independent expletive. Needing to go back and re-parse the associations makes it feel awkward even if it's technically acceptable.
TL;DR: The sentence is grammatical, but "whatever the fuck you want" is easier to parse.