On further analysis what we found that there are three master pages used in SharePoint.
1. Master Page for Site Pages. This Master page is used in home page (default.aspx), WebPages etc..
2. Master Page for System Pages like Document Library Item Form pages (All Items.aspx, NewForm.aspx, EditForm.aspx, etc)
3. Master Page for Application Pages under "Layouts" folder. The application pages uses the "application.master" page.
So in the scenarion, we had set the Site pages to use the master page but not the system pages. When we click on document library we will be landing on the Allitems.aspx which is the View Page (System Page) for the "All Items" View. The System Pages are still using the default master page with the default theme and thats the reason the default theme is rendered for the document library.
To Overcome this issue, we need to use the "MasterURL" and the "CustomMasterURL" property to set the master page of "System Pages" and "Site Pages" respectively. In our custom site definition "Onet.xml" find the "Configuration" we used for your template and add the above mentioned properties to it. Set the master page URL (Master Page gallery path) as the value for this both the properties so that our master page and theme in it will be applied to both Site Pages and the System Pages. Following Code snippet can be used for this: