It seems like every SARS-VoV2-Infektionsschutzverordnung (SARS-CoV-2 Infection Protection Ordinance) is based on the same template.
Relevant to your case is Part 3 of said Ordinance. § 9 (1) states
Furthermore, § 8(1) sentence 1 shall not apply to persons who enter
the Federal Republic of Germany or the state of Berlin only for the
purpose of transit; such persons shall immediately leave the territory
of the state of Berlin by direct route. The necessary transit through
the territory of the state of Berlin is permitted.
This is the same for every Federal State you would cross on your journey to Berlin. How exactly you get there is your own business. You could go by train (be aware of the compulsory-masks during the whole travel, incl. train stations) or – probably the better option when considering you might be infective – rent a car.
According to this article (question 4) the local health authorities (Gesundheitsamt) will be informed of any infections (in the past in Berlin arrivals had to it themselves, but maybe the process is more refined now). The Gesundheitsamt will also decide, what a "suitable acommodation" is (§ 8 (1) of the Ordinance cited above). I guess there are hotels or maybe still congress halls prepared for cases like yours.
Please also be aware that as per § 9 (3) of the Ordinance cited above you need both a negative test result and a medical certificate. According to the website of the test center the test itself will cost you 59 €, the verification of your ID 9 € and the medical certificate an additional 25 €. So, this is cheaper than a voluntary test for German citizens, nice to know.
As to your question of return, I don’t think any airline will let you board if you are Covid-19-positive and/or should be under quarantine. You would have to wait out the whole two weeks.
That said, I would strongly advise against doing such travels without very important reasons. Both due to the possible quarantine and the risk of getting infected/infecting others. But you probably considered this.
Credit:stackoverflow.com‘