When you create the site using "Publishing site" template it activates the feature called "ViewFormPagesLockDown". This feature prevents users from opening any of pages from "_layouts" folder. Unfortunately this is not available with "Team Site" and other templates.
But you can prevent users from accessing application pages (_layouts) by activating this feature manually. This is also helpful preventing search engines from crawling application pages.
To lock down your application pages, you apply the following stsadm command :
stsadm -o activatefeature -url <site collection url> -filename ViewFormPagesLockDown\feature.xml
This can be reversed (unlocked) by following command:
stsadm -o deactivatefeature -url <site collection url> -filename ViewFormPagesLockDown\feature.xml
Note, if you have anonymous access enabled prior to activating this feature, you need to disable anonymous access and then re-enable anonymous access again.
Another similar capability is available for removing people picker AD lookups.
stsadm -o setproperty peoplepicker-nowindowsaccountsfornonwindowsauthenticationmode