The biggest reason why he should not be locked away is that there is something pure and good about his intentions, as misguided and rooted in fantasy as they are. Although he clearly struggles to distinguish between fantasy and reality, at the same time, he is a figure who longs for a sense of purpose and beauty in the world. This is something that even the most cynical among us can sympathise with and appreciate.
Also, although Don Quixote's inability to separate fact and fantasy cause problems, it does not really cause much harm in the big scheme of things. Yes, he is seen as an irritating character by those around him and by those who cross paths with him, but there is nothing harmful or evil about his madness and his struggles to work out what is true and what isn't.
Lastly, we could also argue that Don Quixote should not be locked up because he is on a quest to recover his sanity. As the novel progresses, it is clear that he gradually, bit by bit, becomes more able to discern what is real from what is a product of his imagination, as his final cure and claim of sanity demonstrates. Locking him away when he is mid-way through this process would not have helped him to regain his sanity.