How are textures generated in 3D in compared to 2D
Many procedural texture generation algorithms can be generalized to be n-dimensional. And even if a given algorithm cannot be generalized, the concept that the texture is based on most likely can be, so a new algorithm can be devised for higher dimensions.

Usually, the procedure for generating, let's say, 2d musgrave noise is not much different from the one used to generate 3d Musgrave noise, which is not much different from one used to hypothetically generate 4d musgrave noise, or 5d, and so on...

Also, almost always a high-dimensional texture generation algorithm can be generalized for lower dimensions by discarding high dimensional information. For instance : if you generate perlin noise in a volume (as in 3d noise) and take only a slice out of it, discarding the rest, then you've effectively generated perlin noise on a plane (as in 2d noise), this is most likely what blender does. (in reality most procedural textures are generated per-sample-point so this procedure doesn't really play out as described, you just don't generate samples in the whole volume, just ones that lay on the plane that you are interested in)