Stack Overflow policy is that a user's ability to delete his own content is limited. In some cases you can, in some cases you can't. A full list is at When can't I delete my question?.
The rationale here is that SO is a collaborative site, and you can't delete something on your own if it's proven valuable for others, or if other people have invested time and effort into responding.
So you can't delete an answer that's been accepted (since it's clearly useful to the questions original poster), and you can't delete a question which has upvoted answers (since evidently other people have spent effort writing, and deleting your question would require deleting their answer).
It's definitely not illegal; it's in the site's terms of service (Section 3). There's no lack of internet forums where you can't edit or delete posts once you've sent them! -- but I understand why you'd expect it to be possible on SE, since otherwise editing content is very much a part of the site. So, now you've got the rationale; you may not agree with it, but it's very much consistent with Stack Overflow's goal of being a long-term resource, keeping valuable content regardless of who posted it first.