In Sekiro: Shadows Die Twice, how to go back and get the key after Sekiro kills the centipede can be referenced as follows:
After defeating the centipede monster, I found that the shrine door behind was locked. In fact, the key to the shrine door was in the study on the upper floor of the castle tower. The key is next to Kuro. Put away the key, open the shrine door and go out.