Can I thank websites that host illegal book downloads in the acknowledgements section of my thesis? My stance is that these websites are a great boon to the research community and they were certainly extremely helpful for my research. I think they should be applauded rather than persecuted, and while they may be illegal now, I think a way to make them legal should be found (in the same way I can download articles legally through my university's subscription to all the major publishers and journals).

Can I thank them in the acknowledgements section of my thesis?
You can thank whomever you want in the acknowledgments of your thesis, but there may be consequences that you have to live with.

In my opinion it is a bad idea to admit to illegal activity in a formal document like this.  Once you write that, you cannot unwrite it: it will be archived for the rest of your career.  I don't really think you'd get in any trouble directly, but by doing so you're advertising the fact that you are willing to break rules that you don't like and do so entirely openly.  I think that a lot of potential employers prefer employees who when they break the rules for a good reason, do so more quietly.

I also don't really see what you're gaining by doing this.  A thesis acknowledgment is not a step toward legal free downloading of texts.  I happen to agree with you that "a way to make them legal should be found".  One way I work towards this is that I make all of my lecture notes -- some of which are very close to being textbooks -- freely available on the internet.  Whenever I have spoken with publishing companies, I mention at the first meeting my requirement that my material be made freely available on the internet.  To my surprise, they have not walked out of the room.  I also have largely stopped assigning expensive required texts.

In summary: an acknowledgment to the providers of illegal content is a microscopic flouting of the establishment, not a helpful act.  I recommend that you think a bit more carefully about what you can do to actually improve the situation.