Why is the perfect fourth dissonant in some cases when it does not sound dissonant? When I play it in close position, it does not sound dissonant at all. When I play it as a compound interval, I would kind of agree an extremely excessively tiny bit. Why is it considered a dissonance sometimes when it actually does not?
Dissonance has no universal definition but depends on style and context.
For example, the perfect fourth is a dissonance in the context of species counterpoint. Whether it sounds pleasant, subjectively, is irrelevant: in that domain, it behaves as a dissonance, that must be resolved through falling by step. Again the everyday definition of dissonance is not involved here. In this context, the word dissonant indicates a tension function: the music cannot stop on this note, it must resolve according to the rules of the style.
The consonance of the Perfect Fourth, like all intervals, depends on context. In this video, there's a great example of perfect fourths sounding really dissonant.
Also, certain styles of music treat it different ways. Consonance and dissonance are largely context and culture related in nature, and though people have attempted to quantify them, they really can't be pinned down, other than the ubiquitous "it sounds like...".