How can I make players spawn with a sword after dying?

You need a death Counter first

/scoreboard objectives add deaths deathCount

I recommend functions but you can use a repeat command block and a chain command block, too

/execute as @a[scores={deaths=1..}] run give @s minecraft:iron_sword
/execute as @a[scores={deaths=1..}] run scoreboard players reset @s deaths

Use a scoreboard objective that tracks the time since the player last died.

/scoreboard players add deathTime time_since_death

Then run, in a repeating command block:

/give @a[scores={deathTime=1}] wooden_sword