It looks like the issue is the data you pass to trainNetwork. When you swap the 2nd lstmLayer to have OutputMode="last" then the network only outputs that last LSTM state, the fullyConnectedLayer only operates on that last state, and the loss computed in regressionLayer only uses that last state, and the "actual targets" passed to trainNetwork.
Here's an example:
sequenceLength = 5;
x = {randn(1,sequenceLength)};
y = x+1;
layers = [
sequenceInputLayer(1)
lstmLayer(1)
regressionLayer];
opts = trainingOptions("adam");
net = trainNetwork(x,y,layers,opts);
This LSTM takes in a sequence, outputs a sequence, and trainNetwork trains the network by minimizing the loss between the network output and the target data y. We usually call this sequence-to-sequence.
Now if you instead just want a sequence-to-one case you can do something like:
sequenceLength = 5;
x = {randn(1,sequenceLength)};
y = sum(x);
layers = [
sequenceInputLayer(1)
lstmLayer(1,OutputMode="last")
regressionLayer];
opts = trainingOptions("adam");
net = trainNetwork(x,y,layers,opts);
The various supported response types for trainNetwork are described here https://uk.mathworks.com/help/deeplearning/ref/trainnetwork.html?s_tid=doc_ta#mw_d0b3a2e4-09a0-42f9-a273-2bb25956fe66