Some do and some don’t.
In my first book I knew where it ended as the story was planned out fully. The exact ending came to me as I was finishing the last chapter. I decided to stop it dead at a certain point. Leaving a bad taste in the reader’s mouth and anger. It worked well.
I write short stories with a twist in the tail, the end HAS to be known so that the story can build up to it.
When you start on a journey like writing a book, it is good to plan it out even roughly so that you know in which direction to go. Then get on with it. But in the final few chapters it’s really important to have a sense of the ending. You need a goal, and only when you reach that part will you be able to finish it.