Why do urinary tract infections cause delirium?

Only if septic. Urinary tract infections may complicate with sepsis or septicemia which may affect the brain function and cause delirium.
Complicated. Delirium, or acute confusion, can present in the elderly from a number of medical illnesses like infection, dehydration, meds, cahnge in environment, etc. The likelihood it will happen increases with age and dementia. An already aging sensitive brain responds to any stresses, possibly by getting confused. It is a true medical emergency and needs immediate evaluation and treatment.