ダメだよ花咲、先生に見つかったら色々ヤバいんだからさ
So from what I understand the に takes the meaning of "by" only when used with a passive form. That is when used with passive form the person/object etc marked by に is the one doing the action directly or indirectly.
And when there's no passive form the action is being directed toward the person/object marked by に.
In this case however there is no passive yet it still takes the meaning "by"