American slang: "to give a girl the time" (in J. D. Salinger's The Catcher in the Rye)
Solution 1:
Green's Dictionary of Slang has an entry for "give her the time," defined as of a man, to have sexual intercourse, but the only citation provided is a reference to the Salinger passage discussed here, which appears to leave potentially two open questions, one being whether the phrase was actually ever in slang use outside the realm of fiction, apart from references alluding to Catcher In the Rye.
The second question, as outlined in by the OP, is why:
How come 'give a girl the time' can mean 'have sex with a girl'?
A possible explanation for this is given in the context of the phrase as defined in Cassell's Dictionary of Slang (2005), which defines it as a variant of do her job for her:
do her job for her v. [mid-19C+] of a man, to have sexual intercourse and give a woman an orgasm (cf. give her a tail v.; give her one v.; give her the jampot v.; give her the time v.; ...
This angle suggests that it could be an alteration of "give her a good time," ostensibly referring euphemistically to giving "her" "an orgasm," though we have no knowledge of what evidence Cassell used to categorize the phrase this way.
If the phrase is a true slang phrase that was adopted by Salinger into use by a fictitious character, it seems like a reasonable explanation of the phrase's use. There are plenty of slang terms and phrases that lexicographers take seriously but which have essentially no identifiable primary source examples available.
However, it's worth noting that the phrase might have been a complete invention of Salinger's unless anyone can disprove that by finding other uses in print.
Another possibility
It's also worth considering the similarity to the phrase make time with, meaning "to make advances, to flirt, to court," as in this 1942 citation from GDoS:
He’s one of those cab-Casanova — makes more time than a driver does.
- W. Winchell ‘On Broadway’ 23 Jan. [synd. col.]
Another citation from 1935 might be earlier to follow by context:
Brer’ Rabbit saw he wasn’t makin’ no time wid Miss Saphronie.
- Z.N. Hurston Mules and Men (1995) 109
Solution 2:
Harold Wentworth & Stuart Flexner, Dictionary of American Slang, first edition (1960) has this entry for the expression:
time, give {someone} the To have sexual intercourse with someone. 1951: "Most guys just talked about having sexual intercourse with girls all the time, but old Stradlater really did it. I was personally acquainted with at least two girls he gave the time to." J. D. Salinger Catcher in the Rye, 40f. Not common. Euphem[ism] for give it to {someone}.
Unfortuntely, Wentworth & Flexner doesn't provide an entry for "give it to someone"; but Robert Chapman, New Dictionary of American Slang (1986) offers this:
give it to someone 1 v phr To beat, punish or rebuke: He really gave it to me yesterday after I totaled his car 2 v phr To do the sex act to or with someone: one minute he'd be giving it to her in his cousin's Buick—JD Salinger
The Salinger quotation that Chapman cites also comes from The Catcher in the Rye, and the expression appears there twice in the same sentence:
One minute he'd be giving it to her in his cousin's Buick, the next minute he'd be giving it to her under some boardwalk. It was all a lot of crap, naturally.
So we have the explanation that "give [someone] the time" is a euphemistic form of "give it to [someone]," which is itself so vague as to be effectively a euphemism. Interestingly, by the time of Chapman's update of Wentworth & Flexner, "give [someone] the time" was so out of use that Chapman simply omitted it; Chapman did, however, offer a brief entry for the similar sounding but totally unrelated expression "not give [someone] the time of day":
not give someone the time of day v phr Not do the slightest favor for; not greet or speak to; have contempt for: Like him? I wouldn't give that bastard the time of day
I ran some book and newspaper database searches for "give/gave/giving her the time" in the relevant sense without success. The euphemism may begin and end with Salinger, or it may have a hidden history of regional or even national use. Either way, I suspect that it alludes to the formally benign expression, "give [someone] the time of [that person's] life." Examples of this phrase go back at least to 1905, where a review of Anne Warner's The Rejuvenation of Aunt Mary in the Los Angeles [California] Herald (October 22, 1905) has this:
Well, Jack and some of his college friends give her [Jack's Aunt Mary] such a reception as she never dreamed of; as Jack says, they "give her the time of her life."
The phrase occasionally appears in the context of a couple going out together. For example, from Richard Marsh, A Royal Indiscretion (1909) [combined snippets]:
For some reason she did not care to damp this young gentleman's enthusiasm by directly declining his surprising offer to give her the time of her life ; she diverted the subject.
"Have you come from Cambridge to-day?"
And from Servia Antopolska, "The Tide," reprinted in the [Sydney, New South Wales] World's News (January 23, 1929):
Mr. Silverstein melted in sympathy. "Say, boys." he said, "that girl ought to have a feller. Why don't one of you guys make a date with her and give her the time of her life?"
"Yeh, why don't we?" growled Ike, "and have old lady Goldman suin' for breach of promise? Nix for this baby."
But while the idea of romance may lurk in some early instances of "give [someone] the time of [that person's] life," the suggestion of sex does not—as I read these examples, anyway. Hence "give [someone] the time," in Salinger's usage, contains a new sexual element, whether he borrowed the euphemism from "give someone the time of [that person's] life" or not.