Generally, the EV is calculated assuming random lynches and nightkills (absent information provided by the existence of named Roles or Investigation results). For setups with power roles, the exactly EV becomes increasingly difficult to determine, due to claiming strategies (for example, it may be best for Mafia to fake-claim a role with some probability, rather than always or never).
The argument for equating "optimal" and "random" for the purpose of EV calculation comes from mith:
The short version of the argument: Town's optimal play can be no worse than random lynching; if it were they would just lynch randomly to improve their EV. Mafia playing optimally can also do no worse than the lynches being random - at worst, their optimal play would be "play exactly like you don't know you're Mafia". QED
It is typically assumed that Town should do better than EV - that is, they will lynch better, on average, than random. This effect is most apparent in Nightless games, where the Mafia do not have an opportunity to remove strong town players. However, in other setups, the assumed Town advantage has not been borne out in games played.