I am from Brazil and I'm living in Italy on a tourist visa from past two years. I would like to go to Romania and apply for an Italian student visa and re-enter Italy with the student visa. Is this possible or do I need to go back to my home country and apply for the student visa?
You have to go back to your home country, Brazil to apply/get your new student visa to study in Italy. You cannot go to Romania and apply for a student visa to re-enter Italy. In the student visa application itself, they will ask you to provide proof for legal residence in Romania i.e., you need to either be a permanent resident/resident alien or a citizen of Romania in order to apply/appear for a visa interview at an Italian consulate. And even if you were able to appear for the visa interview at a local consulate, they ask several questions on what is the reason for applying from Romania rather than from your home country and so on.
This also applies to most of the other nationalities trying to enter a new country for higher education. It is always advised to go to their home country and apply for the student visa.
Like many countries, Italy only allows you to apply for a visa from a country in which you're legally resident. You don't have to be a citizen, but you can't just be a visitor. The website for the Italian consulate in Romania is only available in Italian and Romanian, but the Italian consulate in the UK notes that to apply for a study visa you must include proof of your legal residence in the UK, and the form linked from the website of the consulate in Romania implies a resident permit is required for applicants who aren't Romanian citizens.
To apply for your student visa, you must return to Brazil, unless you have resident status in another country, in which case you could apply from there.