A very large number of medical conditions can cause psychosis, sometimes called secondary psychosis. Examples include:

disorders causing delirium (toxic psychosis), in which consciousness is disturbed
neurodevelopmental disorders and chromosomal abnormalities, including velocardiofacial syndrome
neurodegenerative disorders, such as Alzheimer's disease, dementia with Lewy bodies, and Parkinson's disease
focal neurological disease, such as stroke, brain tumors, multiple sclerosis, and some forms of epilepsy
malignancy (typically via masses in the brain, paraneoplastic syndromes)
infectious and postinfectious syndromes, including infections causing delirium, viral encephalitis, HIV/AIDS, malaria, syphilis
endocrine disease, such as hypothyroidism, hyperthyroidism, Cushing's syndrome, hypoparathyroidism and hyperparathyroidism; sex hormones also affect psychotic symptoms and sometimes giving birth can provoke psychosis, termed postpartum psychosis
inborn errors of metabolism, such as Wilson's disease, porphyria, and homocysteinemia.
nutritional deficiency, such as vitamin B12 deficiency
other acquired metabolic disorders, including electrolyte disturbances such as hypocalcemia, hypernatremia, hyponatremia, hypokalemia, hypomagnesemia, hypermagnesemia, hypercalcemia, and hypophosphatemia, but also hypoglycemia, hypoxia, and failure of the liver or kidneys
autoimmune and related disorders, such as systemic lupus erythematosus (lupus, SLE), sarcoidosis, Hashimoto's encephalopathy, anti-NMDA-receptor encephalitis, and non-celiac gluten sensitivity
poisoning, by therapeutic drugs (see below), recreational drugs (see below), and a range of plants, fungi, metals, organic compounds, and a few animal toxins
sleep disorders, such as in narcolepsy (in which REM sleep intrudes into wakefulness)
parasitic diseases, such as neurocysticercosis
huntington disease