Updated:

1. Darken the screen

/effect give @a minecraft:darkness 30 0 true
/effect give @a minecraft:blindness 5 0 true

Darkness pulses like a nearby warden; blindness is stronger. On Bedrock write /effect @a darkness 30 0 true. See the effect command.

2. Midnight and thunder

/time set midnight
/weather thunder 6000

3. Creepy sounds (Java)

/execute as @a at @s run playsound minecraft:entity.warden.heartbeat master @s ~ ~ ~ 1 1
/execute as @a at @s run playsound minecraft:ambient.cave master @s ~ ~ ~ 1 1
/execute as @a at @s run playsound minecraft:entity.ghast.scream master @s ~ ~ ~ 1 0.5

A pitch of 0.5 makes a sound low and slow. See the playsound command.

4. Jump scare in a corridor

# repeat, always active
execute as @a[x=40,y=64,z=0,dx=2,dy=2,dz=2,tag=!scared] at @s run playsound minecraft:entity.enderman.scream master @s ~ ~ ~ 1 0.8
# chain, always active
title @a[x=40,y=64,z=0,dx=2,dy=2,dz=2,tag=!scared] title {"text":"Behind you","color":"dark_red"}
tag @a[x=40,y=64,z=0,dx=2,dy=2,dz=2] add scared

The tag makes it once per player. Pair it with traps.

5. Ghostly particles (Java)

/particle minecraft:sculk_soul ~ ~1 ~ 1 1 1 0.02 30

See the particle command.

Troubleshooting

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.