A stress function is a mathematical construct used in elasticity theory to simplify the process of solving complex stress analysis problems by ensuring equilibrium and compatibility conditions are automatically satisfied. It helps in reducing the number of governing equations, making it easier to solve for stress distributions in materials under external loads.