I believe it is important to keep in mind that the sentence in question is part of a song. Music, like poetry, is an art form that requires interpretation. Taking a single sentence from a song and trying to interpret it strictly on the basis of English language rules is bound to add confusion, especially for a non-native speaker. Furthermore, this is a song from a musical, and that particular genre of theatre and film absolutely relies on the synergistic combination of music, lyrics, script, scene, and acting to fully convey its message.
Consider the song "People Will Say We're in Love", from another musical production from the same era, called Oklahoma!. https://youtu.be/VEwVAV3VPw4
The lyrics ask, "why do people think we are in love?" and then list many ways that the couple could avoid doing things that make others gossip about them this way. Taken out of context, the lyrics mostly imply that these two people do not like each other, yet there are some phrases that imply the opposite. For example, she calls him, "Sweetheart" just after telling him to return some personal possessions of hers. And he says, "Your hand feels so grand in mine" just after admonishing her, "Don't keep your hand in mine." However, from watching the performance, it is quite clear that they are indeed in love and trying to pretend otherwise. Watch how she looks at him with passion or how he holds her hand while singing those lyrics, and the meaning of the words is completely different. (Much like real life, one might say.)
The lyrics alone also do not readily show that the song is a duet, which adds a great deal of context to the words. In the spoken script, just preceding the song, the male and female leads are having a conversation about an upcoming picnic, which the woman plans to attend with someone else. The man wants her to attend the picnic with him, and she says it will cause people to "talk" (gossip). They begin to discuss how folks love to gossip and, in the style of a musical, this conversation morphs into a song. Much more about their true relationship is implied by their flirtatious acting during the song than the lyrics themselves provide. By the end of the song, they are holding hands, smiling, and cheek-to-cheek, while the male lead sings, "Don't dance all night with me...People will say we're in love." Contradictory? Yes! And that is exactly the point.
The Sound of Music is a film and theatre production of the same era and genre as Oklahoma! so there are many style similarities. In order to fully understand the song lyrics, you must also understand the full context of the scene with Maria and the nuns, including what has happened just before the song begins.
We already know that Maria is out in the hills enjoying nature (and singing, of course!). The nuns are quietly discussing the new "recruits" and the subject of Maria comes up. They talk about her lack of discipline and yet she is also likable. As with all musicals, this conversation segues into a song (https://youtu.be/yYvyh3IIdDk). At the end, Maria herself comes running into the abbey, hair a mess, late for prayer again, and stops short in front of the sisters who stop singing. She tidies herself and tries to walk away with decorum, then the nuns resume singing the final "impossible problem" line: "how do you hold a moonbeam in your hand?"
The entire scene must be taken together, along with prior scenes which establish that Maria herself IS the problem that the nuns do not know how to solve. It is certainly not standard English to write or speak the way this sentence is written, but in a musical for stage or film, the rules do not always apply. In fact, it is in large part, the breaking of rules -- like solemn nuns randomly breaking into song -- that makes the musical theatre genre so unique and engaging.