Several classes of chemicals can be said to be psychedelics or hallucinogens. Mainly they are classified as being a tryptamine, phenethylamine, dissociative (NMDA antagonist) or deliriant (anticholinergic).
Psychedelics all have different mechanisms of action according to their chemical structure. Most of the commonly known hallucinogens such as LSD, psilocybin, DMT, mescaline, DOM are chemically either tryptamine or phenethylamine. The effects of tryptamines and phenethylamines are attributed to their actions on the 5-HT (serotonin) receptor system.
This topic is complex and not fully understood. It would probably take me hours to accumulate all the basic information and put it in a context that people with no knowledge of how the brain works could understand. If you're really interested you can start your research here.