Only certain spells turn weapons magical.
The spell Magic Weapon specifies:
You touch a nonmagical weapon. Until the spell ends, that weapon becomes a magic weapon with a +1 bonus to Attack rolls and Damage Rolls.
Likewise, the spell Elemental Weapon states:
A nonmagical weapon you touch becomes a magic weapon.
If casting any spell on a weapon makes it a magic weapon, these spells wouldn't have to specify that they turn nonmagical weapons into magic weapons.
For an in-universe explanation, only spells that explicitly add magic to a weapon would affect whether a weapon was magical or not. Since spells like light or minor illusion don't deal damage on their own, and don't fundamentally modify whatever they're cast on, they don't add the magical quality to the weapon. Additionally, polymorphing a weapon only changes its physical form, and doesn't add any magical properties.
Developer intent supports this.
As Purple Monkey points out, Jeremy Crawford, the lead rules designer for 5e, confirms this:
What just happened?
@RCPlemons
@JeremyECrawford Would casting the light cantrip on a weapon render it a magic weapon in regards to resistance to non magical weapons?
Jeremy Crawford
@JeremyECrawford
@RCPlemons No.