Thank you for posting your code.
Based on the Neural Network Toolbox documentation here, updating the net.trainFcn will reset the net.trainParam to the default values for the new function. So changing the net.trainFcn to trainscg changes the net.trainParam to the defaults listed here. These defaults include having the epochs set to 1000.
To fix this, just move the assignment to the net.trainFcn to before any updates to the net.trainParam.