Which is better (and why)?
Which feature should I attach this task to?
To which feature should I attach this task?
The first phrasing is what one would use in casual conversation; it does a good job of establishing the subject, object, and verb to a listener whereas the second phrasing takes some "decoding", in my opinion.
The "rule" that you can't end sentences with prepositions is a myth; it's generally agreed that ending sentences with prepositions is fine as long as the preposition is not extraneous (i.e. you wouldn't have the same meaning by removing it.) So, the first sentence is not ungrammatical.
However, the idea of this rule indeed exists because as TLP said, it is a bit of mouthful. It might make sense to go with an alternate phrasing.
I am not sure the first one is quite proper English, but I am sure it is passable. If you read it out loud, though, it is quite a mouthful.
The second one is, IMO, clearer, as it narrows the scope of the question straight away: "To which feature.."
An alternative to these two is:
To which feature should this task be attached?