In your example, the difference in nuance is based on what the subject of the sentence is. Technically, the subject of "마세요" is "you", but the subject of "안 돼요" is "something"
I'll show you with direct translation
그러지 마세요. = You shouldn't do this.
이러면 안 돼요. = If you do, something won't work.
"안 돼요" is "안"(not) plus "돼요". "돼요" has many meanings, but the closest one in this example is literally "work".
So, "이러면 안 돼요." is a more indirect way of saying "You shouldn't do that" by stating the circumstances of the situation rather than speaking directly to the other person, and can have the effect of being polite. These expressions that omit
The expression "돼요" with the subject(something) and use "돼요" are omitted is used so common in Koreanfrequently that it's hardpointless to recognizespecify that athe subject has beenis omitted, but it's worth knowing its origins to understand the subtle differences in meaning.