You are trying to print a pyramid of N lines with two for-loops using range. So the sum of of the lengths of your two ranges should be N.
Now consider the sum of for i in range(1, N - 1) and for i in range(1, N - 2) with some large N. Take N=99 for example:
len(range(1, 99 - 1)) + len(range(1, 99 - 2))
>>> 193
This is your first mistake. The function only works with N=5 because of the two minuses you have chosen for your ranges. What you need to do here is to rewrite your math:
len(range((99+1)//2)) + len(range((99-1)//2))
>>> 99
Note that I removed the starting value from ranges, as it is not needed here. By default, range starts to count from 0 and ends one number before the ending value.
The second mistake you have is with how you are printing the bottom half of the triangle. Basically, you have tried to reverse everything to print everything in reverse, but that has somehow broken the logic. What here we want to do is to print k empty spaces for each line, incrementing k by two for each line.
Function with minimal fixes:
N = int(input())
k = 1
for i in range((N+1)//2):
for j in range(1, N + 1):
if(j <= N - k):
print(' ', end = '')
else:
print('*', end = '')
k = k + 2
print()
k = 2
for i in range((N-1)//2):
for j in range(1, N + 1):
if(j > k):
print('*', end = '')
else:
print(' ', end = '')
k = k + 2
print()