Wigs became almost instantly fashionable after Louis XIII started wearing one in 1624 to hide his baldness, and were almost universal for European upper & middle class men by the beginning of the 18th century. Their main purpose was to mask receding or graying hair, and as a fashion item.
One excellent source is the very detailed diary of Samuel Pepys (1633 - 1703), where he mentions his and others' wigs several times:
Saturday 9 May 1663
At noon dined at home with a heavy heart for the poor man, and after dinner went out to my brother’s, and thence to Westminster, where at Mr. Jervas’s, my old barber, I did try two or three borders and perriwiggs, meaning to wear one; and yet I have no stomach [for it,] but that the pains of keeping my hair clean is so great.
Saturday 29 August 1663
Abroad with my wife by water to Westminster, and there left her at my Lord’s lodgings, and I to Jervas the barber’s, and there was trimmed, and did deliver back a periwigg, which he brought by my desire the other day to show me, having some thoughts, though no great desire or resolution yet to wear one, and so I put it off for a while.
Monday 26 October 1663
Thence Creed and I to one or two periwigg shops about the Temple, having been very much displeased with one that we saw, a head of greasy and old woman’s haire, at Jervas’s in the morning; and there I think I shall fit myself of one very handsomely made.
Friday 30 October 1663
Then by coach with my wife to the New Exchange, and there bought and paid for several things, and then back, calling at my periwigg-makers, and there showed my wife the periwigg made for me, and she likes it very well, and so to my brother’s, and to buy a pair of boddice for her, and so home, and to my office late, and then home to my wife, purposing to go on to a new lesson in arithmetique with her.
Saturday 31 October 1663
And also two perriwiggs, one whereof costs me 3l., and the other 40s. — I have worn neither yet, but will begin next week, God willing.
Monday 2 November 1663
The King staid so long that we could not discourse with the Duke, and so we parted. I heard the Duke say that he was going to wear a perriwigg; and they say the King also will. I never till this day observed that the King is mighty gray.
Tuesday 3 November 1663
By and by comes Chapman, the periwigg-maker, and upon my liking it, without more ado I went up, and there he cut off my haire, which went a little to my heart at present to part with it; but, it being over, and my periwigg on, I paid him 3l. for it; and away went he with my owne haire to make up another of, and I by and by, after I had caused all my mayds to look upon it; and they conclude it do become me; though Jane was mightily troubled for my parting of my own haire, and so was Besse, I went abroad to the Coffeehouse, and coming back went to Sir W. Pen and there sat with him and Captain Cocke till late at night, Cocke talking of some of the Roman history very well, he having a good memory. Sir W. Pen observed mightily, and discoursed much upon my cutting off my haire, as he do of every thing that concerns me, but it is over, and so I perceive after a day or two it will be no great matter.
Sunday 8 November 1663
I found that my coming in a perriwigg did not prove so strange to the world as I was afear’d it would, for I thought that all the church would presently have cast their eyes all upon me, but I found no such thing.
Monday 9 November 1663
Up and found myself very well, and so by coach to White Hall and there met all my fellow officers, and so to the Duke, where, when we came into his closett, he told us that Mr. Pepys was so altered with his new perriwigg that he did not know him.
Friday 13 November 1663
After dinner came my perriwigg-maker, and brings me a second periwigg, made of my own haire, which comes to 21s. 6d. more than the worth of my own haire, so that they both come to 4l. 1s. 6d., which he sayth will serve me two years, but I fear it.
While the first quote implies hygienic reasons, every other quote is about fashion and personal vanity ("I never till this day observed that the King is mighty gray."). Hans Zinsser, in Rats, Lice and History suggests that wigs, or more accurately the fact that men shaved their heads to wear them, protected them from lice. However, Samuel Pepys doesn't seem to agree, he regularly had to clean his wigs from lice:
Monday 18 July 1664
Thence to Westminster to my barber’s, to have my Periwigg he lately made me cleansed of its nits, which vexed me cruelly that he should put such a thing into my hands.
Wednesday 27 March 1667
Having put him in a way of preparing himself for the voyage, I did go to the Swan, and there sent for Jervas, my old periwig maker, and he did bring me a periwig, but it was full of nits, so as I was troubled to see it (it being his old fault), and did send him to make it clean
Thursday 4 April 1667
Up, and going down found Jervas the barber with a periwigg which I had the other day cheapened at Westminster, but it being full of nits, as heretofore his work used to be, I did now refuse it, having bought elsewhere.