In the Torah, the word מדה means "measurement". Example:
Exodus 26:2 (Sefaria translation)
אֹ֣רֶךְ ׀ הַיְרִיעָ֣ה הָֽאַחַ֗ת שְׁמֹנֶ֤ה וְעֶשְׂרִים֙ בָּֽאַמָּ֔ה וְרֹ֙חַב֙ אַרְבַּ֣ע בָּאַמָּ֔ה הַיְרִיעָ֖ה הָאֶחָ֑ת מִדָּ֥ה אַחַ֖ת לְכָל־הַיְרִיעֹֽת׃
The length of each curtain shall be eight and twenty cubits, and the breadth of each curtain four cubits; all the curtains shall have one measure.
There are many other examples. However, I am unaware of any place in the Torah where the definition of the term is "behavior".
It seems that in the Mishnah, the word is frequently used to mean "behavior" , "temperament" or "character trait" as in:
Pirkei Avot 5:10 (Sefaria translation):
אַרְבַּע מִדּוֹת בָּאָדָם. הָאוֹמֵר שֶׁלִּי שֶׁלִּי וְשֶׁלְּךָ שֶׁלָּךְ, זוֹ מִדָּה בֵינוֹנִית. וְיֵשׁ אוֹמְרִים, זוֹ מִדַּת סְדוֹם. שֶׁלִּי שֶׁלָּךְ וְשֶׁלְּךָ שֶׁלִּי, עַם הָאָרֶץ. שֶׁלִּי שֶׁלָּךְ וְשֶׁלְּךָ שֶׁלָּךְ, חָסִיד. שֶׁלִּי שֶׁלִּי וְשֶׁלְּךָ שֶׁלִּי, רָשָׁע:
There are four temperaments among men: the one who says "what is mine is mine, and what is yours is yours" -- that's an [average] temperament. And there are some who say that is the temperament of Sodom. [A second type is one who says] "what is mine is yours, and what is yours is mine" -- [that's an] am ha'arets (uneducated person). [A third type is one who says] "what is mine is yours, and what is yours is yours" -- [that's a] pious person. [A final type is one who says] "what is yours is mine, and what is mine is mine" -- [that's a] wicked person.
What is the connection (if any) between these two definitions, and why the change in meaning?