Was Machiavelli a humanist?

Yes, he was, and I'm posting a famous "Letter to Vettori" that shows him carrying classical works around by day and working in his study at night.

Roman humanists were employed mainly by the Vatican and helped with the restoration of the Papacy in Rome after Avignon. They were also involved with the creation of the Vatican Library, helping with selection and study of ancient manuscripts.

Machiavelli on the other hand was a Florentine humanist, and not in the same situation. He was employed by the Florentine Republic until 1512 when the Medici were restored. His brand of humanism is more independent, more classically focused, and definitely not concerned with supporting the Papacy, which he saw as the major cause of Italian political fragmentation and weakness. So it's fine to talk about humanism in regard to Machiavelli, just realize he is in a different category.

There were humanists in all cities of Italy, and one of them, Lorenzo Valla, working for the King of Naples, who was opposed to the Papacy, wrote a famous treatise called On the False Donation of Constantine, which for the first time questioned the historical authenticity of the Papal claim to temporal power. So it is definitely true that not all humanists were "in the Papal camp," but it is also pretty much true that humanists needed jobs and patrons, so reflected the political position of the people that hired them.

In this sense, Machiavelli is almost unique, because he had lost his job (with a Republican Florentine government to which he owed his true allegiance). So in a real sense he was free in exile to express his own opinions.