Generally, the EV is calculated assuming random lynches and nightkills (absent information provided by the existence of named Roles or 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