How can inanimate objects function as edim and/ or edot in the Tanakh?
- הַגַּל (Gen. 31:48)
- הַשִּׁירָה (Deut. 31:19)
- הַתֹּורָה (Deut. 31:26)
- הַשָּׁמַיִם והָאָֽרֶץ (Deut. 31:28)
- הָאֶבֶן (Jos. 24:27)
Probably each example you cite above could be answered separately; here are some thoughts:
Gen. 31:48: The Alshich asks your exact question and explains that גלעד is equivalent in Mispar Koton (a form of Gematria) to 17 - Hashem's Great and Holy Name - in order to hint that the true witness in this case is Hashem (see Rashi to 31:44).
Alternatively, perhaps the meaning of עד here is more in the context of a physical marker than a someone supplying testimony.
The Torah Shleima (footnote 117) quotes a Midrash that Billiam's foot was crushed on this very pile of rocks when attempting to curse the Jews, since he was a son of Lavan and was breaking the pact by crossing the pile for evil purposes. Therefore the pile exacted retribution on him - in keeping with the law that "The hand of the witnesses shall be first against him".
Deut. 31:19: See Rashi to 31:21 as explained by Sifsey Chachomim. If the Jews claim that they were not warned of the bad things that would result from their misdeeds, this song will serve as testimony to the contrary. I.e. עד here means "evidence". (This answer probably covers most of the other questions).
Deut. 31:28: Rashi (32:1) brings two explanations why heaven and earth were chosen to bear witness: either because the heaven and earth endure forever, or because they will be the ones to reward or punish the Jews by giving or withholding produce. The first answer suggests that heaven and earth could in fact come and refute the Jews' claim (and are not considered inanimate). Based on the second answer, they are considered witnesses because they have the means to inflict punishment.