Some parts of this concept go back at least as far as "The Jameson Satellite" by Neil R. Jones, Amazing Stories, July 1931. It is possible that the complete concept of Human brains enslaved and used as computers or computer components goes back to Pohl and Kornbluth's Wolfbane, serialized in Galaxy October & November, 1957, as suggested in Tobias's answer or Walter M. Miller's "I, Dreamer" Amazing stories June-July, 1953, as suggested by Mike Stone.
In the Star Trek episode "Miri" October 27, 1966, Doctor McCoy ordered a "biocomputer" sent down from the ship to help him study the disease. Presumably it was a computer programmed to do biological research calculations and simulations, etc.
MCCOY: A veritable zoo of bacteria. Beam down a biocomputer and a portable electronic microscope. If I'm dealing with viruses, I'll need better equipment than I have here.
In James Blish's adaptation of "Miri" in Star Trek, January 1967, he described the "biocomputer" as a biological computer using a cat's brain for processing data. Which is not exactly "captive human brains" but similar. This was published before "Spock's Brain" was broadcast on September 20, 1968.
In the Lost in Space episode "Invaders from the Fifth Dimension", November 3, 1965, aliens take Will Robinson to use his brain to control their space/time vehicle.
In Larry Niven's "Becalmed in Hell" Fantasy & Science Fiction July 1965, the narrator "Howie" travels to Venus with Eric Donovan, a cyborg spaceship (only the brain is left of Dononvan's body, with the spaceship itself being his new body). They quarrel, and later Donovan sends Howie a note of reconciliation, signed "Donovan's brain". This is not "captive human brains used for computers" but close.
Niven may have been inspired by Anne McCaffrey's "Ship Who Sang" series, with starships and other operations controlled by the thoughts of disabled persons - selected soon after birth - encapsulated within them. The first story "the Ship Who Sang" was published in Fantasy & Science Fiction April 1961. McCaffrey said her inspiration was an earlier story about a woman searching for her son's brain which was being used as the automated pilot of an ore ship. Disabled rights activists have called the "brainship" arrangement in the stories a form of slavery for persons with disabilities.[1]https://en.wikipedia.org/wiki/The_Ship_Who_Sang
Niven's mention of "Donovan's Brain" is a joke about Kurt Siodmak's 1942 novel Donovan's Brain where the brain of millionaire W.H. Donovan is kept alive in a jar and seeks to enslave others. It was adapted into three movies" The Lady and the monster (1944), Donovan's brain (1953), and The Brain (1962).
Captain Future, who first appeared in Captain Future magazine in 1940, had several assistants including the brain of the brilliant scientist Simon Wright encased in a floating case.
L. Sprague DeCamp's Science Fiction Handbook (1953) mentioned an early science fiction story whose title I forget where someone traveled into the far future and found that the last descendants of humanity were giant brains who did nothing but sit around and think and killed them all in disgust. According to user14111 the story is "Alas, All Thinking" by Harry Bates, Astounding, June, 1935.
"The lotus Eaters" by Stanly G. Weinbaum Astounding Stories April 1935 involved the discovery of intelligent plants on Venus who were far more intelligent than humans but had no will power or emotions or desires and so were very much like living computers. I have often thought that it would make sense for the humans to cultivate those plants and use them as computers.
in H.P. Lovecraft's "The Whisperer in Darkness", Weird Tales August 1931, the Mi-go aliens from Yuggoth (possibly Pluto) and other worlds can put the brain of a willing or unwilling human in a brain cylinder with life support and interfaces with the outside world. The plot suggests that in some cases it is a form of captivity. This is before the Hawk Carse story "The Affair of the Brains" by Harry Bates and Desmond W. Hall, Astounding, March 1932, mentioned in user14111's answer.
"The Jameson satellite" by Neil R. Jones, the first in a long series, was published in Amazing stories July 1931. Friendly cyborg aliens revive the brain of the dead professor Jameson and put it in a robot body like theirs and he joins their band of space explorers.
J.D. Bernal, in the non fiction The World, The Flesh, and the Devil (1929) suggested many futuristic concepts including disembodied brains which have since been common in science fiction and maybe in some cases in real life.
In H.G. Well's The War of the Worlds (1898) scientific progress has rendered the Martians' bodies unnecessary and their bodies have atrophied to giant brains with tentacles and a few other minor organs attached. In his The First Men in the Moon (1901) The Grand Lunar has become even more like an emotionless living computer and might be considered to be the slave of his subjects.
So these are the examples I could remember and look up. None are exactly
using captive human brains as computers
but some come quite close and every part of that concept is found in combination with some other parts of it several times.
The first use of the complete concept of enslaved human brains used a computers may be in Pohl and Kornbluth's Wolfbane Galaxy October, 1957, as suggested by Tobias, or Walter M. Miller's "I, Dreamer" Amazing stories June-July, 1953, as suggested by Mike Stone.