There is no way to change the entities' properties at runtime. Each prototype is build durind data stage, while loading factorio. The reseach is capped at level 50 to limit the impact of prototype generation, although even while playing heavili modded factorio, if there are 10 types of solar panel, they generate 50x10=500 prototypes, when the limit is over 65.000, so still less than 1% of the game. In addition, solar panels don't have moving animations, so the RAM usage is really irrelevant.
There might be lag spikes when replacing the entities, true, but that wont happen more than once per technology, which is a really rare event overall.