Neural net layer that preserves spatial information
Rather than trying to predict each value explicitly, you could pick a parametric function that you think might be expressive enough to describe your target function (for example, a polynomial of order 6), and get your network to learn the parameters of that polynomial that give you a minimum loss. This is basically polynomial regression.  Since your function is periodic you might use a more cycle-based basis set, like linear combinations of sine waves.

For example:

1) Input data to the network
2) output a set of values that you treat as parameters to your function
3) for each target point, compare it to the predicted value from your function
4) calculate a loss (like mean squared error) based on the difference between the function predictions and the targets.

Using a function will (1) restrict the space of possible outputs, and (2) make nearby outputs be self-similar.