If file page contains more than 100 templates and the licence template happens not to make it into 100 first templates returned by the API, licence is not recognized.
See for instance: https://commons.wikimedia.org/wiki/File:Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg
All templates should be fetched to avoid such problems, see tlcontinue parameter https://commons.wikimedia.org/w/api.php?action=help&modules=query%2Btemplates