We are practicing collective code ownership. To my understanding this means that any developer can change any line of code to add functionality, to refactor, fix bugs or improve designs.

But what about a complete rewriting of code from a developer who is still in the team? Should I ask him first? What is the best practice?

I think good communication is always the best practice.  Talk to the developer and see if there's a reason why it's coded the way it is.  It may be that they have been meaning to get back and refactor it for ages, it may be that they did it that way for a very good reason, or it may be that you both can learn something from the conversation.

Going in and rewriting without prior communication is a recipe for ill will.
