What do you want to happen when the end of the 5-to-25-minute time interval is over?
static unsigned long startTime = 0;
int maxBrightness = map(analogRead(brightnessPot), 0, 1023, 0 255);
int maxSeconds = map(analogRead(timePot),0, 1023, 5*60, 25*60);
int elapsedSeconds = (millis() - startTime) / 1000;
// Assuming you want to start over at dark when the time limit is up
if (elapsedSeconds >= maxSeconds) {
startTime = millis();
elapsedSeconds = 0;
}
analogWrite(outputPin, map(elapsedSeconds, 0, maxSeconds, 0, maxBrightness));