It's called interning a warship.
Sri Lanka is temporarily taking custody of the warship. It's allowed under international law.
This is the first time a neutral country has interned a warship after world war II. Last one was the Italian warship Attilio Regolo which was interned by Spain in 1940s.
It's actually a major diplomatic achievement by Sri Lanka. If the US attacks the ship now, it implies they are attacking Sri Lanka not Iran, which would be a serious breach of international law.
US no longer respects international law though.