Which event is used to programatically apply master page or theme?

PreInit is the only event where you can apply master page or theme programatically. This can not be done in any other event. PreInit event was introduced in ASP.NET 2.0 Page Life Cycle sice ASP.NET 2.0 introduced the concepts of master page and themes.