I have a few sites that are indexed in Google (when I do the "site:url" operator), but they do not show up for their main keyword in like the first 20 pages.
I know that this happens to new sites, but a few of these sites are like 6+ months old and had been in the #3 position all this time for their main keyword. Then they disappeared for a few weeks and then came back for a few days again, but now gone again.
I've experienced this with new sites, but usually after building some backlinks they become stable and keep their position.
So what is the main reason while my sites which have been around for a while have disappeared from the SERPs while still being indexed? What can I do to get them back in the SERPs?
This can be a difficult situation to diagnose. It could be a bug at Google; it could be a penalty; it could be a loss of some key backlink power - and there are many other possibilities, too.
Do you have a WebmasterTools account? That's the first place I'd check. Look for messages from Google and look at the "Top Queries" report. Look for Crawl Errors, and so on.
If you do see your target keyword in Top Queries, click on the plus sign and look at all the various positions where Google has ranked your site during whatever time period you want to set. Then notice what kind of click-through rates you are getting.
It seems very likely that many sites do not hold their rankings if the title and snippet are not attracting clicks, and Google Webmaster Tools is the only place I know of you can see IMPRESSION data and not just traffic data.