If you compare the length of text and reverse, you will see that reverse has one extra character, even though the two strings seemingly appear to be the same.
In your snippet posted above, reverse doesn’t end up being " madam". Instead of a blank space, a null character (denoted by '\0') has ended up being the first character of your reverse string. So, reverse is actually "\0madam" which appears as "madam" on your screen. On screen, the text and reverse strings will appear indistinguishable, but if you check their length, you will see that the length of text is 5 while that of reverse is 6.
(You can also confirm this by a statement such as std::cout << (reverse == '\0') << "\n" which will output 1 if true and 0 if false)
If you edit the loop initialization to int i = text.size() + 1; or some other out of range index number, you will see undefined behavior (your output could be gibberish or some other unpredictable behavior). Many languages (like Python) will throw an error. But in C/C++, the onus is on the programmer to respect the range/bounds.