Can I apply for a United States visa while I am leaving for Spain from India?
Your point of departure is unimportant. You must apply from your place of residence. That the consulate considers you a resident of the United States depends in part on your immigration status in the United States. If you have status B-1 or B-2, you will not be able to apply to the United States, with a few exceptions. If you are in another status for more than six months, they are more likely to accept your application.
But you probably should not apply to the consulate of Spain. You have to apply in the country that is the main destination of your trip. If the main destination can not be determined by the purpose of your trip, then you must look at the length of stay and apply to the country in which you will spend the most time, namely Hungary.
Do I have to apply for a student visa or tourism because the dates available at the Spanish consulate for a tourist visa are May 7 (which is impossible for me) and student visas are numerous?
A Spanish student visa is a long-stay visa for which you must be enrolled in a university in Spain. You need a short stay visa (sometimes called a "tourist visa").
Then will the visa application in a consulate suffice, since it will be a Schengen visa according to my knowledge?
Yes, you should only get one short stay Schengen visa. Check appointment times at the Hungarian consulate unless something related to the purpose of your trip makes Spain the main destination.