Post the game, generally KID is a system and you shouldn't fall into such an issue. Either you blindly played the KID with little regard to your opponent's designs, or they have some serious pawn structure problems and holes somewhere.
King's Indian white castles Q side

I play the modern defence against 1. d4 and this looks similar to some positions I've faced. I am by no means an expert but it looks like you need to push pawn to c6 so you can get counter play with your queen. The pawn push f5 is not that bad generally if white has castled king side.
I think generally if white avoids castling, rip open the middle and foce him to castle. You are castled and developed so ripping up the middle is good for you. Don't start any pawn pushing near your king (except maybe h5 if he starts rolling his h pawn towards you) if white has not castled king side. If he castles queen side you need to start pushing pawns towards him because if his king side attack reaches your king faster you're doomed and fast.
You with all the luft around your king want to keep the center as closed as possible! c5 is a good idea then try to shut down his king side rolling and close the kingside if possible but this isn't as important as your king should be safe with all your pieces there, Just try not to give him open lines.
If white castles kingside, then you shouldn't play f5. You should keep the tension on the kingside as that is your normal side of play in the KID, while beginning the b6, b5 push on the queenside (when possible).

this is not too bad. Note generally when White castles Kingside against the KID, he aims to launch a queenside attack. By castling Queenside, it is limiting themselves in terms of a queenside attack. While you may not know what to do, your oppenent will struggle to find an attack as well. White doesn't have an intiative, black could try f4, move his King to Kf7 and then play Rh8, advancing the pawns.

I was thinking maybe ...c6 but White's pieces control nearly all the queenside squares! It is generally inadvisable to open files where the opponent has a space advantage, but if the king is on that side that could change things but I only have a few pieces aiming there! Maybe I could do a positional king side attack, still advancing the pawns after ...f4.
What do you do with black in the KID when white castles queenside and the center is closed with a pawn structure of d6, e5, f5 (with possibilities of ...f4), e4, d5, c4? If I push my kingside pawns it seems risky because white may just use the open files to attack my king, but I'm confused because black has more space on the kingside so he should control that area. If he tries the queenside it seems quite difficult because trying to open the c file with ...c6 doesn't seem to achieve much because white controls the queenside with his bishops while black hardly has anything aiming there. Or should I not play ...f5 when white hasn't commited to castling? but then what do I do instead?