Quick fix without touching settings: open Terminal and run
caffeinate -dis
The Mac stays awake until you close that Terminal window or press Control + C.
For a lasting change: System Settings > Battery > Options and turn on “Prevent automatic sleeping on power adapter when the display is off”. On a desktop Mac it’s under System Settings > Energy.