How does an engineering undergraduate apply for master in humanities? I am doing undergraduate in engineering but I want a transition to humanities for masters (history, anthropology).  

How do I do this?
Should I take  prerequisite courses at a community college or through online/distance education?
While I think the other way around (transitioning from the humanities to the sciences) might be harder, if you can demonstrate that you are serious and prepared to undertake graduate training in the humanities, it is definitely doable. 

In my sociology department (PhD track, we didn't have a separate MA program and most entered straight after undergraduate school), many of my colleagues did not have any sociology training. While most of them came from related fields of economics, political science, and psychology, there were people with math and physics backgrounds and these were sometimes the people who were doing the most innovative and interdisciplinary work. The selection committee was fine with accepting them as long as their proposed research area fit with the department faculty's research and they showed promise as a sociologist. 

While a degree in the field isn't necessary, make sure you address how you have been working to fill the gap you have on your CV. A personal statement will be a good place to address this. In addition, you can take additional courses, read as many works in your proposed field, and try to have a well developed study plan to give confidence to the committee that you are as competitive as the other candidates. It might be a good idea to also build contacts with professors in schools that you are applying for and go talk to them to see if they will be interested in working with you. If you plan to specialise in a society other than where you are based in (especially in case of anthropology), make sure you demonstrate regional expertise, language skills, knowledge of the society, or maybe work and/or living experience. Also, since those departments (in case of a PhD program) will likely ask for a writing sample, start working on one well in advance so the committee can see that you can indeed to the work in the proposed field.