When you do something that requires WordPress write to the filesystem, it does a check to see if it has permissions to do so by writing a temp file. If this check fails it will ask for FTP details in order to write the files to your server.
EDIT
look in wp-admin/includes/file.php
, line 843, for the get_filesystem_method
function that does this check.