Just composing in the head is a nice first step, but merely thinking about something makes it easy to gloss over flaws in your thinking that you have to face when wrting something down (if you do non-stream-of-consciousness writing).
On the other hand you have to think about things only tangentially related to the actual problem you are writing about like style, grammer and finding the right words.
So there are advantages and disadvantages to actually writing stuff down.
Are you saying you don't learn anything from thinking through how to write a big piece of code before you write it?
The vast majority of bugs I find after writing the code are trivial. Certainly, I learn something from writing it, but I find that if I just start writing without thinking about it first, especially for larger projects, I don't end up where I want to and have to scrap large pieces of it.
Writing helps you get the details straight, but thinking is essential for designing the big picture.
Writing may help you organize your thoughts, but it's not necessary.