The King Cobra does this as a defense display to scare off other snakes or predators by making themselves appear extra-huge.
King Cobras are also the only snake to build a nest for their young, so they also do this to protect the nest, their family, and territory