Step 1: First, let's create 3 scoreboards that will be used to store the X, Y, and Z coordinates
scoreboard objectives add deathPosX dummy
scoreboard objectives add deathPosY dummy
scoreboard objectives add deathPosZ dummy
Step 2: Place 3 command blocks in a row. The first one should be an Impulse block with a button, followed by 2 Chain blocks. Set the Chain blocks to "Always Active"
Use the following commands in each, following the order the command blocks were placed:
execute store result score @p deathPosX run data get entity @p LastDeathLocation.pos[0]
execute store result score @p deathPosY run data get entity @p LastDeathLocation.pos[1]
execute store result score @p deathPosZ run data get entity @p LastDeathLocation.pos[2]
These commands will store the coordinates of the player's death into the scoreboard
Keep in mind that this will only work for the nearest player; you can change @p to a specific player's name or to something like @e[tag=test], for example
You can also use a Repeat block instead of an Impulse one if you want to update the coordinates constantly instead of pressing the button each time
Step 3: Let's display the coordinates of where the player died in the chat using the tellraw command
Place this command in an Impulse command block with a button, and press it to see the result!
tellraw @p ["",{"text":"Death Coordinates: ","color":"red"},"\n",{"text":"X: ","color":"yellow","bold":true},{"score":{"name":"@p","objective":"deathPosX"},"color":"green"},"\n",{"text":"Y: ","color":"yellow","bold":true},{"score":{"name":"@p","objective":"deathPosY"},"color":"green"},"\n",{"text":"Z: ","color":"yellow","bold":true},{"score":{"name":"@p","objective":"deathPosZ"},"color":"green"}]