A batter can leave the field in the middle of an innings without being dismissed in the usual way. What happens next depends on why they left.
Retired hurt
If a batter leaves because of injury or illness, they are retired hurt and recorded as not out. They can come back later in the innings when a wicket falls or another batter retires.
Retired out
If a batter walks off for any other reason, such as a tactical decision to bring in a bigger hitter, they can only return with the opposing captain’s permission. Otherwise they are recorded as retired out, which counts as a dismissal.
Retiring out has become a genuine tactic in T20 cricket. R Ashwin became the first player to do it in the IPL in 2022, making way for a faster-scoring batter late in the innings.