If you enter under the Test&Go program, you would need to do a PCR test and isolate at an approved hotel until getting a negative result (usually takes half a day). After that you're free to do what you like, including leaving the country. (This assumes the test result is negative, of course!)
If you're no longer in Thailand on day 5, you obviously don't have to do the second test.