How do i make a tool like a diamond pickaxe only be able to break a certain block and be unbreakable in minecraft java edition 1.15?

That command only works in Minecraft versions lower than 1.13. This is the command for 1.13+:

/give @p minecraft:diamond_pickaxe{CanDestroy:["minecraft:stone", "minecraft:stone_bricks"], Unbreakable:true}

1.13 changed many of the technical aspects of Minecraft. This was called "The Flattening". For more information see https://minecraft.gamepedia.com/Java_Edition_1.13/Flattening.