We have a consensus view that questions asking for re-writes of code are off-topic
Citation needed. I don't agree about this at all.
Refactor Linq Expression
Simple code refactoring in javascript
These questions are not off-topic. This is closed as unclear what you are asking because there is absolutely no description whatsoever about what the code does. There are a lot of "How can I refactor this code"-requests that are completely on-topic. In fact, I'd say most of them are.
Making this Pygame code object-oriented
This question is not off-topic because it asks to make the code OOP, it's off-topic because the OP is saying "I get this syntax error now, tried multiple things without progress." and quotes the syntax error in the question.
So of all three examples of questions that are "questions asking for re-writes of code", NONE OF THEM are off-topic for that reason.
I think the questions you are asking about are what I'd like to call "specific refactoring requests", which is basically when a question asker has self-reviewed their code beforehand, identified something that needs to be changed, then comes here to get more detailed help in accomplishing this. As rolfl pointed out in a comment, this discussion has existed before on meta and I've shared my opinion about it before. I don't think we should be so nit-picky here so that we essentially tell OP's "Your current question is off-topic because you are formulating it (this way), if you instead would formulate it (that way) then it would be on-topic".
There's nothing wrong with asking for re-writes of code, all our on-topic questions here are about rewriting code in one way or another.