NASA/Getty Images
You get arrested when you return to Earth.
The principal basis of determination is the Outer Space Treaty of 1967.
(GA Resolutions Pertaining to the Peaceful Uses of Outer Space)
Article VIII of that treaty says:
A State Party to the Treaty on whose registry an object launched into outer space is carried shall retain jurisdiction and control over such object, and over any personnel thereof, while in outer space or on a celestial body.
As far as the ISS [International Space Station] is concerned, there is an Intergovernmental Agreement (IGA) signed by all partners in 1998 that further specifies legal authorities aboard and in the proximity to the ISS: Page on State
With regard to criminal conduct, it states:
Canada, the European Partner States, Japan, Russia, and the United States may exercise criminal jurisdiction over personnel in or on any flight element who are their respective nationals.
In a case involving misconduct on orbit that: (a) affects the life or safety of a national of another Partner State or (b) occurs in or on or causes damage to the flight element of another Partner State, the Partner State whose national is the alleged perpetrator shall, at the request of any affected Partner State, consult with such State concerning their respective prosecutorial interests.
An affected Partner State may, following such consultation, exercise criminal jurisdiction over the alleged perpetrator provided that, within 90 days of the date of such consultation or within such other period as may be mutually agreed, the Partner State whose national is the alleged perpetrator either: (1) concurs in such exercise of criminal jurisdiction, or (2) fails to provide assurances that it will submit the case to its competent authorities for the purpose of prosecution.
There are also documented codes of conduct for astronauts: 14 CFR Part 1214 - SPACE FLIGHT
In addition, if the offender is a member of the U.S. military (as many astronauts are), then they can also be prosecuted under the UCMJ (Uniform Code of Military Justice).