When nobody can contribute meaningfully anymore. Basically, when the original post has been exhausted of any potential discussion. Either that or it goes off the first few pages.
If it's a support thread, we'll usually lock it if someone (who isn't the OP) posts in it after several months have passed or the OP has left the site.